This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Is the model right or wrong?
Posted by Mike Mannion on 10 Nov 1998, 7:56 AM
It never does any harm to bare the following in mind: There is no such thing as a "correct" object model, only a a model which is more or less useful relative to a particular problem domain.
But just to add my two cents worth on this particular domain: A "useful" way to model an employee in many circumstances is as a Person which maintains an aggregate of PersonRoles.
A person's roles may include instances of EmployeeRole, ManagerRole, ExploitedLikeHellThenFiredRole. Some roles may, of course, be mutually exclusive, yet people can still serve multiple roles e.g. employee/manager.
The person class therefore possesses features which are truely fixed e.g. place of birth, birthday etc., plus the aggregate of dynamic roles.
As someone else wrote already, this basically follows a state or strategy pattern.
The book "Java Design 1st ed." (P.Coad, Printice Hall) decipts this using dandy little diagrams of hat-wearing people, where hats correspond to the roles the people play.
The same text also has a good summary of the inheritance vs composition argument. (2. edition apparantly comes out sometime soon.)