in reply to perspective and object-disorientation
Of course, an Employee may also be a Musician, Artist, Trainspotter (in their spare time)I think I see your error here. When a Person becomes employed by an Organization, then his role within that Organization becomes that of Employee. This does not affect his role within a family, nor does it affect his Hobbies or whatever.
One way of handling this within your object model is to look at using the Decorator pattern. Consider the following code from your Domain objects:
What's happening here is that the Employee class delegates all the 'Person' stuff that's relevant to the organization to its decorated Person object, and handles all the organization specific methods and attributes itself. Thus, the Organization only ever deals with Employees. (In a real (commercial) Object model of course, Employee would probably end up being a 'whole' class, without needing the flexibility of the Decorator pattern, simply because no other entities need to make use of an underlying Person object.)package Organization; ... sub recruit { my $self = shift; my $new_hire = shift; $self->add_employee(Employee->wrap($new_hire)); return $self; } package Employee; sub wrap { my $class = shift; my $person = shift; $class->new->set_person($person); } sub set_person { my $self = shift; my $new_person = shift; $self->{person} = $new_person; return $self; } sub surname { my $self = shift; $self->person->surname; } sub employee_number { my $self = shift; $self->{employee_number}; } ...
As for the Musician/Artist/Trainspotter thing, just give your Person class a list of Role objects to which the person delegates appropriate methods (though getting that behaving neatly may take a little more work on the programmers part (and there are several different ideas about what is 'right') so I'm going to resort to a handwave at this point.
Father/Husband/Buddy etc are all relationships rather than intrinsics. Depending on what your object model dictates these may end up being full on decorater classes or simple references from one Person to another.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: perspective and object-disorientation
by Ctrl-z (Friar) on Jan 19, 2003 at 21:57 UTC | |
by pdcawley (Hermit) on Jan 19, 2003 at 22:32 UTC | |
by Ctrl-z (Friar) on Jan 19, 2003 at 22:58 UTC |