in reply to OO Pattern Container x Elements and Method Chaining
Container = SharedHouse Element = Person ->do_something = ->pay_rent
this used to work as long as one Person could only live in ONE house at a time.
my $cont = SharedHouse->new('Prag'); my $elem = Person->new('Egon'); $cont->add_elem($elem); # method chaining $cont->get_elem('Egon')->pay_rent();
Now the requirement changed to manage multiple houses in the same program with overlapping sets of inhabitants.
my best guess is that get_elem should now return an object of a new class Inhabitant pointing to one SharedHouse and one Person
- handles methods involving the Container directly
- delegates other methods to an object Person
$elem1 = $cont1->get_elem('Egon'); $elem2 = $cont2->get_elem('Egon');
but both are internally pointing to the same Person 'Egon'
$elem1->{person} == $elem2->{person}
such that
$elem1->pay_rent() pays the rent for the SharedHouse object in $cont1
but
$elem1->comb_hair() delegates to $elem1->{person}->comb_hair()
I hope it's clearer now. :)
(the real model is even more complicated, since the container is actually a matrix of two types of elements and values in the cell. Think of objects of type Room like $kitchen, and $Egon->owns("Kitchen", "Table"); )
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: OO Pattern Container x Elements and Method Chaining (House, Person, Inhabitant)
by NERDVANA (Deacon) on Oct 09, 2021 at 13:54 UTC | |
by LanX (Saint) on Oct 09, 2021 at 17:21 UTC | |
by LanX (Saint) on Oct 09, 2021 at 14:06 UTC | |
Re^2: OO Pattern Container x Elements and Method Chaining (House, Person, Inhabitant)
by karlgoethebier (Abbot) on Oct 09, 2021 at 12:10 UTC | |
by LanX (Saint) on Oct 09, 2021 at 12:17 UTC | |
by karlgoethebier (Abbot) on Oct 09, 2021 at 21:58 UTC | |
by LanX (Saint) on Oct 09, 2021 at 23:00 UTC |