Java Reference
In-Depth Information
This design fails in real-world situations, in which one person operates
simultaneously in more than one role. For example, an engineer might
be an acting manager in a group and must now appear in two guises.
As another example, a teaching assistant is often both a student and a
staff member at a university.
A more flexible design would create a
Role
class and extend it to create
classes for roles such as
Manager
. You would then change the design of
the
Employee
class to have a set of
Role
objects. A person could now be
associated with an ever-changing set of roles in the organization. We
have changed from saying that a manager IsAn employee to saying that
manager IsA role, and that an employee can HaveA manager's role as
well as other roles.
If the wrong initial choice is made, changing deployed systems will be
hard because changes could require major alterations in code. For ex-
ample, methods in the first employee database design would no doubt
rely on the fact that a
Manager
object could be used as an
Employee
. This
would no longer be true if we had to change to the role-based design,
and all the original code would break.