Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualfrob

Posted 27 April 2013 - 09:49 PM

Yes.

Keeping the two together, any object that can be displayed by the gui's stats system should implement a common interface. Perhaps call it IHasStatsPack.

On many of our studio's projects we have established the pattern of interfaces named IHasFoo or IFooable.

The interface would just be something simple:

class IHasStatsPack {
Stats_Pack* getStats() = 0;
}

Then your gui class can accept an object of type IHasStatsPack.

That's really all the gui cares about. The gui doesn't care if the object is an enemy or a player or some other game object. All it cares about is that the object has the getStats() function that returns a valid stats structure for display.

Now anyone who creates game objects can use your gui to display any object they want. It may happen that the game will only ever display stats for enemy units. But maybe not. If someday a future programmer needs to build some helper class somewhere and wants to pass that to your gui, they just need to implement the IHasStatsPack interface.

Everybody wins with this kind of design.

#1frob

Posted 27 April 2013 - 09:48 PM

Yes.

Keeping the two together, any object that can be displayed by the gui's stats system should implement a common interface. Perhaps call it IHasStatsPack.

On many of our studio's projects we have established the pattern of interfaces named IHasFoo or IFooable.

The interface would just be something simple:

class IHasStatsPack {
Stats_Pack getStats() = 0;
}

Then your gui class can accept an object of type IHasStatsPack.

That's really all the gui cares about. The gui doesn't care if the object is an enemy or a player or some other game object. All it cares about is that the object has the getStats() function that returns a valid stats structure for display.

Now anyone who creates game objects can use your gui to display any object they want. It may happen that the game will only ever display stats for enemy units. But maybe not. If someday a future programmer needs to build some helper class somewhere and wants to pass that to your gui, they just need to implement the IHasStatsPack interface.

Everybody wins with this kind of design.

PARTNERS