hihi. that was funny, thanks for the humor in the last reply (the one with changing getType() in getRole()). Not the method name was a problem but my way of thinking. I'll fix the damn OO model.
After a long and painfull browsing activity (I mean really) I found this, posted by Greg Barton:
"This is an OO question, really.
The main question is: is a Teacher ALWAYS a User, and is a User ALWAYS a Person? If so, then use inheritance Person -> User -> Teacher. If a Teacher can sometimes be a User and sometimes not, use delegation. (A Teacher can contain a User object which contains all info used to access the system.)
Maybe if you thought of the User object more as a UserProfile object, that would help. (UserProfile being only the information used to access the system, not the identity of the user. (little "u" intended)) Then you have Person -> Teacher with a Person or Teacher containing a UserProfile object.
"
and after, this:
"Basically your examples fit into the "Role" (or Facet) pattern. A good example of this can be seen in security. (like operating system users, with roles like Admin, Guest, User, etc...) Each user has a different level of access defined by the roles they've been assigned, and a user can have many roles. (i.e. a user could have student, teacher, or principal level access...or all three, though that would probably be redundant)
So, in your case, you could have a Person object with potentially many (aggregated) Roles. (Teacher, Student, Principal) When the Person accessed the system, their Role list would be checked and their access level determined."
Thank you Greg Barton for thislike I said, I'll fix the damn OO model :-).
And I'll get a job in constructions maybe. not as an architect, of course :-)
|