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:
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};
}
...
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.)
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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|