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
subjectfact 
player-rolehas definition 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 player2001-08-30 14:57:00.0
has antipatterns merging all the properties and behaviours into the Player class which however, creates an overly complex class - much of the power of object orientation is lost2001-08-30 14:57:00.0
has context
  • 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.
2001-08-30 14:57:00.0
has forces 2001-08-30 14:57:00.0
has problem How do you best model players and roles so that a player can change roles or possess multiple roles?2001-08-30 14:57:00.0
has related patterns Abstraction-Occurrence pattern2001-08-30 14:57:00.0
has solution
  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.
2001-08-30 14:57:00.0
is a subtopic of 6.4 - The Player-Role Pattern2001-08-30 14:57:00.0
is an instance of design pattern2001-08-30 14:57:00.0
design patternhas name2001-08-30 14:55:16.0
has references one or more references which indicate who developed or inspired a pattern2001-08-30 14:55:16.0
should be illustrated using a simple diagram2001-08-30 14:55:16.0
should be written using a narrative writing style2001-08-30 14:55:16.0
patternshould be as general as possible2001-08-30 14:56:56.0
should be described in an easy-to-understand form so that people can determine when and how to use it2001-08-30 14:56:56.0
should contain a solution that has been proven to effectively solve the problem in the indicated context2001-08-30 14:56:56.0

Next design patternproxy    Updesign pattern    Previous design patternobserver