Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
YouTube Security VideosAndroid Police: Samsung is smashing records! #shorts #tech #phones(21.09.2026 um 13:55 Uhr)
YouTube Security Videosheise & c't: Bundesnetzagentur wollte diesen Futterautomaten verbieten(21.09.2026 um 13:53 Uhr)
YouTube Security VideosNeil Patel: Your Google Traffic Isn't An Asset It's A Loan #shorts(21.09.2026 um 14:05 Uhr)
Windows Tipps & SecurityF-14 A Tomcat Top Gun endlich als Revell Klemmbausteinmodell erhältlich(21.09.2026 um 14:27 Uhr)
Sichere ProgrammierungShow the Hand-Back Sample Before Approving an Agent Score(21.09.2026 um 14:15 Uhr)
Sichere ProgrammierungHybrid retrieval in one Postgres query: RRF over tsvector + pgvector(21.09.2026 um 14:15 Uhr)
YouTube Security VideosAndroid Police: Samsung is smashing records! #shorts #tech #phones(21.09.2026 um 13:55 Uhr)
YouTube Security Videosheise & c't: Bundesnetzagentur wollte diesen Futterautomaten verbieten(21.09.2026 um 13:53 Uhr)
YouTube Security VideosNeil Patel: Your Google Traffic Isn't An Asset It's A Loan #shorts(21.09.2026 um 14:05 Uhr)
Windows Tipps & SecurityF-14 A Tomcat Top Gun endlich als Revell Klemmbausteinmodell erhältlich(21.09.2026 um 14:27 Uhr)
Sichere ProgrammierungShow the Hand-Back Sample Before Approving an Agent Score(21.09.2026 um 14:15 Uhr)
Sichere ProgrammierungHybrid retrieval in one Postgres query: RRF over tsvector + pgvector(21.09.2026 um 14:15 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

[BlindSpot] Log 03. Let's follow the SOLID principles : SRP

BlindSpot Github SOLID Principles SOLID principles are the five design principles of object-oriented programming. Today I will be solving SRP and DIP issues in my code. SRP(Single Responsibility principle) SRP is the…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

BlindSpot Github






SOLID Principles



SOLID principles are the five design principles of object-oriented programming.

Today I will be solving SRP and DIP issues in my code.





SRP(Single Responsibility principle)



SRP is the principle that a class(object) should have only one responsibility(function).

When this principle is not followed, maintenance problems can easily arise, such as when one function is modified, other functions that seemed unrelated stop working.

In my code, I have several classes that handle various functions.

ServerPacketHandler performs both the role of routing packets and the actual business logic(login processing, room creation logic, etc.) at the same time.

Session has a mixed role of being responsible for socket communication (Receive/Send) and a data container that holds user status information (playerId, name, room).

PlayerManager handles all the 'player' related functions, including session management, ID generation, name mapping, token management, etc.

So, I will separate all of these functions.





DIP(Dependency Inversion Principle)



DIP is the principle that higher-level modules should depend on abstractions (interfaces) rather than on the concrete implementations of lower-level modules.

Failure to adhere to this principle can lead to increased dependencies between classes, such that modifying one class can lead to subsequent modifications to other classes affected by the change. Furthermore, if a test class lacks an interface, a new class must be created to perform the same functionality.

In my code, there are currently a large number of Manager objects that use the Singleton pattern. I'll split some of these out to adhere to the Dependency Independent Programming (DIP) principle.





Let's follow the SRP principle





ServerPacketHandler.cpp



ServerPacketHandler is both receiving and processing packets.

I will change its role to only receive packets and forward them to other new service files.

I made AuthService(Login), RoomSerivce(JoinRoom, MakeRoom), GameService(In game operations to add later).




//Before
void ServerPacketHandler::Handle_MAKE_ROOM_REQUEST(std::shared_ptr<Session> session, blindspot::MakeRoomRequest& pkt) {
if (session->room.lock()) {
// Already in a room
blindspot::MakeRoomResponse res;
res.set_result(blindspot::MAKE_ALREADY_IN_ROOM);
session->Send(blindspot::PacketID::ID_MAKE_ROOM_RESPONSE, res);
return;
}
std::string title = pkt.room_name();
int32_t maxPlayers = pkt.max_players();
std::string password = pkt.password();
//...omission
}

//After
void ServerPacketHandler::Handle_JOIN_ROOM_REQUEST(std::shared_ptr<Session> session, blindspot::JoinRoomRequest& pkt) {
RoomService::JoinRoom(session, pkt);
}









Session.h



Session.h currently contains both socket communication and player information (ID, name, room). We'll separate this into a communication object (Session) and a game object (Player).

I made Player object, and insert id,name,room informations.




//Models/Player.h
class Player {
public:
int32_t id;
std::string name;
std::mutex _nameLock;
std::weak_ptr<GameRoom> room;

void SetName(const std::string& playerName) {
std::lock_guard<std::mutex> lock(_nameLock);
name = playerName;
}

std::string GetName() {
std::lock_guard<std::mutex> lock(_nameLock);
return name;
}
};
//Network/Session.h
class Session : public std::enable_shared_from_this<Session> {
public:
Session(tcp::socket socket) : socket_(std::move(socket)) {};
std::shared_ptr<Player> player_ ;

std::string _sessionKey;
//...
}









PlayerManager.h



Currently, PlayerManager manages everything from sessions, authentication, to player data.

So I'm going to break this down into PlayerManager, AuthManager, and SessionManager.




//PlayerManager.h
class PlayerManager {
static std::atomic<int32_t> playerIdGenerator_;
static std::mutex name_mutex_;
static std::map<int32_t, std::string> playerIdToName_;
public:
static PlayerManager& Instance();
int32_t GeneratePlayerId();
void RegisterPlayerName(int32_t playerId, const std::string& name);
void EditPlayerName(int32_t playerId, const std::string& newName);
std::string GetPlayerNameById(int32_t playerId);
};
//AuthManager.h
class AuthManager {
static std::mutex token_mutex_;
static std::map<std::string, int32_t> sessionKeyToPlayerId_;
static std::mutex name_mutex_;
static std::map<int32_t, std::string> playerIdToName_;
public:
static AuthManager& Instance();
static int32_t GetPlayerIdBySessionKey(const std::string& token);
static std::string GenerateSessionKey();
static void RemoveSession(const std::string& token);
static void RegisterSession(const std::string& token, int32_t playerId);

};
//SessionManager.h
class SessionManager {
std::mutex sessions_mutex_;
std::set<std::shared_ptr<Session>> sessions_;

public:
static SessionManager& Instance();
void Add(std::shared_ptr<Session> session);
void Remove(std::shared_ptr<Session> session);
void Broadcast(uint16_t id, google::protobuf::Message& msg);

};









In Conclusion



Before the project grew any larger, I refactored the code to align with the SRP principle. Next time, I'll try refactoring to align with the DIP principle mentioned above.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten [BlindSpot] Log 03. Let's follow the SOLID principles : SRP

Thematisch verwandte Begriffe: BlindSpot, Lets, follow, SOLID · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94097 | A vulnerability was determined in Netcore NBR200V2 1.3.241127.071246. Th…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick