Skip to main content
gamedev.net
🔒 Locked

Class structure

Started by elvman 0 replies 1k views
Original Post
elvman
elvman
Hi! I am makking a multiplayer game, but I came up with following problem. I have read about 4 books and browsed hundreds of web pages about design patterns last week. They all explain types of design patterns very detailed, but none of them show a real-world usage. My problem is that i have three classes: Application, Network and UserManager. Application has exactly one instance of Network and one of UserManager. When a client connects to the server Network creates a user instance in UserManager. Then UserManager uses Network to send a message to all other clients, that a user has been created. So the realtionship of both is: UserManager <-> Network. I can't imagine which pattern to use, because I need many instances of Application (can't use singleton) and as stated in many web sites: dependency injection is evil. I use ActionScript for client and C++ for server (both of them must use the same pattern and code should look the same). Thanks in advance!
ToohrVyk
ToohrVyk
Quote:
Original post by elvman
So the realtionship of both is: UserManager <-> Network. I can't imagine which pattern to use, because I need many instances of Application (can't use singleton) and as stated in many web sites: dependency injection is evil.
There's not so many choices available here: either your dependency is hardcoded, or it's injected, or it doesn't exist. Given that in your example it does have to exist, yet cannot be hardcoded because that would need global identifiers, the only solution left is to inject it. Of course, if the network class only needs to create users, you probably only need to inject an user-creation adapter to the user manager, instead of injecting the entire user manager.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.