Abstract Entity

Motivation

You've adopted the Entity pattern but you're finding that each concrete implementation shares a large proportion of the same state.

Description

The abstract entity implements the entity pattern and acts as a foundation for the rest of your game objects. It implements of the state and behavior common to most of your game objects. Oftentimes, the abstract class leaves its state protected or exposed through methods so that child classes can perform game specific operations.

Interface

Could also consider adding a destroy() method which cleans up the class and calls onDestroy(). — aschearer 2008/07/01 09:12

Advantages

Implementing the common state and behavior in a base class allows you to rapidly prototype new game objects. It also can make implementing complicated inter-object logic easier since all objects derived from the abstract entity can alter their brother's state.

Drawbacks

Adopting this pattern can lead to subtle bugs if you are not careful. It tends to lead to a break in encapsulation. As more state is pushed up to the base entity the pressure to open up that data as public or protected increases. This can lead to children who carry useless state. Worse it can also lead complicated bugs wherein two entities affect each other's private state with unexpected results.

design_pattern/abstract_entity.txt · Last modified: 2008/10/19 18:54 by aschearer
Back to top
Creative Commons License Valid CSS Recent changes RSS feed Valid XHTML 1.0