A
RoleObject is a
DesignPattern used for implementing
TypeMigration (or something resembling it) in a language which doesn't have it. A common example is given in
EmployeeTypes, concerning the need to promote an employee from a programmer to a manager. If in an OO system, "programmer" and "manager" are different types/classes, how is this done?
With
RoleObject's (an example of the
HandleBodyPattern), we construct a "wrapper" object (of class Employee), which clients used. We then create various role objects (
ProgrammerRole,
ManagerRole) which represent the actual functionality of the specific roles. Changing the employee's type (for a promotions) involves replacing the
ProgrammerRole with the
ManagerRole. Since the "role" objects are not held by clients directly (clients only hold references to the external Employee object), this change is automagically propagated to all references to the Employee.
Quite different from
RoleObjectPattern, but identical to
StrategyPattern.