player-role | - Create a «Player» class to represent the object that plays different roles.
- Create an association from this class to an abstract «Role» class, which is the superclass of a set of possible roles.
- The subclasses of this «Role» class encapsulate all the properties and behaviours associated with the different roles.
- 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 player | 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 lost | 6.4 - The Player-Role Pattern | | design pattern |