Re: Single-table Inheritance w/ one-to-many
Re: Single-table Inheritance w/ one-to-many
- Subject: Re: Single-table Inheritance w/ one-to-many
- From: Arturo PĂ©rez <email@hidden>
- Date: Sun, 25 Dec 2005 21:04:45 -0500
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@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden