====== Entity ====== ==== Motivation ==== You want to create multiple objects in a game which need to be rendered and interact with each other. However you are finding that your various game objects share most of the same information and behavior. ==== Description ==== The entity pattern describes an interface to encapsulate the properties and behavior common to all game objects. For example, in almost every game the game objects have a position and dimensions to keep track of. Additionally, game objects generally need to perform a set of common operations such as render and update. ==== See Also ==== * [[Abstract Entity]] * [[EntityGroup]] * [[Active Entity]] * [[Tangible Entity]] ==== Interface ==== {{:design_pattern:entity_uml.png|}} You could also consider adding a unique id to the entity and a corresponding getID() method. --- //[[aschearer@gmail.com|aschearer]] 2008/07/01 09:05// ==== Advantages ==== The obvious benefit of adopting the entity pattern is to consolidate behavior into a top level class thus reducing the amount of code you have to write to introduce new objects. On top of that, by making game objects conform to a single interface you greatly reduce the barrier to adding distinct game objects to your game. Finally when each of your game objects implement a single class you can employ the [[proxy]] pattern and implement a [[EntityGroup]]. ==== Drawbacks ==== If you aren't careful you can end up pushing a lot of behavior into this interface. You'll know this is happening when you leave many methods unimplemented in concrete classes. When this happens it's probably a sign that you should adopt more than one top level interface.