On Dec 25, 2005, at 5:07 AM, Christian Brunschen wrote:


On 24 Dec 2005, at 23:29, Drew Thoeni wrote:


The problem comes in when I am trying to allow a user to create (or edit, but we never get that far) a new record. If no employee has more than one sub-class, things are rosey. However, as soon as an employee has more than one flag checked (that two or more of these are true: isOwner, isConsultant, or isClient), WO believes the wrong Class is being returned an gives an error. This error is the result of a page where popup fields exist to select an owner, consultant, and client to assign to a project.


An object in Java (and indeed most languages) can be of exactly one class. It can never be of more, or less, than one class; it can't usually even change its class during its lifetime.

Basically, you can't use subclassing and entity inheritance to model what you are trying to do.

Read Head First Design Patterns Chapter 10 for the problems with trying to model state with inheritance. You have an object that can be in one or more of the states (Owner, Consultant, Client).

You simply need one single Employee class, with the attributes to specify what sort of employee it is - isConsultant, isClient. I'd actually not have an 'isOwner' attributes, but instead have a relationship from the Employee to the project(s) that thsi employee owns. If the employee owns at least one project, then they are per definition a project owner.

You may be able to use this approach for all three states. Essentially, compose your Employee object out of Owner, Consultant and Client objects. If an Employee has-A Project then it can behave like an owner (for that Project), etc.

Good Luck and Happy Holidays.
-arturo

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to