Actor-Role Pattern

Other Names

Actors are sometimes called participants. Roles are sometimes called behaviors.

Problem

An actor plays many roles. For example, a person can play the role of child, parent, spouse, employee, and customer.

Just as the role played by an actor can change, the actor playing a role can change.

Identifying actors with the roles they play can lead to replication of personal data such as address and phone number. This can lead to inconsistencies if this information is changed in some places but not others.

Solution

The Actor-Role pattern is a basic pattern that decouples identity (the actor) from behavior (the role).

Here's the basic pattern:

Variations of the pattern allow the association to be one-way and allow different multiplicities.

Think of this diagram as a template in which Actor and Role are parameters that can be replaced by classes and interfaces:

Examples of actors include:

Person, Organization, Agent, Robot, Organism

Examples of roles include:

Employee, Customer, Supplier, Nurse, Doctor, Patient, Teacher, Student, Commander, Buyer, Seller

The association can be bi-directional or not. In the unidirectional case it's possible to navigate from a role to the actor who currently plays it:

class Actor {
   private String name;
   private String address;
   private String phone;
   // etc.
}

class Role {
   private String description;
   private Actor actor;
   // etc.
}

An interesting elaboration of the Actor-Role Pattern is the Agent-Role Pattern.