hi everyone !

I'm working on a network strategy game with 3 components one reffere will define the mission and 2 players will make moves and attacks in a turn based way . in the end of each turn , the reffere will generate a rapport of each player action .

i want to make an object oriented design to implement this game in java . i'm thinking about using the observer and strategy pattern . i will be thakful for every help or idea to help me achieve my design . thanks for your time !

1 Year
Discussion Span
Last Post by btissam

I'm not sure where you intend to use the Observer pattern. It's a common way to attach a GUI to a model, or to allow a "referee" to watch players that can move in real time, but for a strict turn based game the ref just needs to access the player's info after they have both played.
In my opinion, using the Strategy pattern is often a poor work-around for a incomplete class model. If you get a good class structure then appropriate strategies (methods) will be selected automatically by method overloading or run-time binding.

I would start with the game's class model. If/when you find difficulties in specific implementation points, then look for a helpful pattern.


hi James , thank you for your time . i was planning for using the observer methods so to set the class army as observer in order to transmit orders to the rest o the units .
another question please , the players will need to create and adjest their army before starting the game . the army must have a detailled Hierarchy of divisions , brigade , units ... . which pattern do ou think is suitable ? i've read about the factory pattern nut i don't know if it's the one i need . Thank you for the help .


You wouldn't use Observer to transmit stuff down a hierarchy. Since each unit will presumably have a list of the units directly below it, it can simply call their appropriate methods. You would use Observer where class A needs to know what's happening in class B without class B having any hard-coded knowledge of A. (Eg a GUI needing to reflect changes in the game classes without the game classes having any hard-coded GUI links).

You need Factory when just calling a few constructors isn't good enough (because the number of options and alternatives is large, or maybe unknown to the code that is calling the constructor). If you don't need it, don't use it.

It seems to me that you are too focussed on patterns at this stage. Just get a first draft of your game classes as a starting point.


Got it ! , thank you very much for your time , i will first draft the games classes as u suggested . thank you !

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.