Object Oriented Software Engineering   View all facts   Glossary   Help
subject > pattern > design pattern > player-role
Next design patternproxy    Updesign pattern    Previous design patternobserver   

player-role comparison table
Subject have solution have related patterns have context have forces have problem has definition have antipatterns is a subtopic of is a kind of is an instance of
design pattern zero or more related design patternsa contextone or more forcesa sentence or two explaining the main difficulty being tackledA pattern useful for the design of softwarezero or more antipatterns - solutions that are inferior or do not work in this context with the reason for their rejection6.1 - Introduction to Patternspattern 
player-role
  1. Create a «Player» class to represent the object that plays different roles.
  2. Create an association from this class to an abstract «Role» class, which is the superclass of a set of possible roles.
  3. The subclasses of this «Role» class encapsulate all the properties and behaviours associated with the different roles.
  4. If the «Player» can only play one role at a time, the multiplicity between «Player» and «Role» can be one-to-one, otherwise it will be one-to-many.
Abstraction-Occurrence pattern
  • A role is a particular set of properties associated with an object in a particular context.
  • An object may play different roles in different contexts.
How do you best model players and roles so that a player can change roles or possess multiple roles?A pattern in found in class diagrams in which one class (the player) has several associated role classes. Instances of the role classes can change over the lifetime of a playermerging all the properties and behaviours into the Player class which however, creates an overly complex class - much of the power of object orientation is lost6.4 - The Player-Role Pattern design pattern

Next design patternproxy    Updesign pattern    Previous design patternobserver