On Thu, 06 Mar 2003 04:19, Paul wrote:
> > Leave them out to carry on with the status quo of a myriad of subtly
> > different, non-interchangable approaches to associating classes.
> TMTOWTDI?
> Still, though your point is valid if I understand it, it will always be
> possible to create "non-interchangable approaches", and we don't want
> to dictate methods if we can help it.
> I think I need an example....unfortunately I'm at work and haven't the
> time to properly peruse the one you offered. Thus I must apologize, and
> wait for more input.

Consider this excerpt from the test script:

my $joe = new Person(name => "Joe Average");
my $car = new Object(description => "Red Car");

$car->set_owner($joe);

ok($joe->posessions->includes($car), "Joe owns car");

The `Object' class has an association which it calls `owner', to class 
`Person' (note: not all associations will be restricted to a particular 
class).  This is a collection that can only have one element so it is 
implemented with a reference.

The `Person' class has an association which it calls `posessions' to class 
`Object'.  This is an unordered collection that can hold many elements so 
it is implemented with a Set::Object.

They are the same relationship, and so setting the relationship from one 
direction affects the other direction.

So, it makes sense to allow the same methods to access and update the 
collections.

is($joe->get_posessions(0), $car, "Joe's first posession is his car");
ok($joe->posessions->includes($car), "Joe's posessions are a set");
ok($joe->posessions_includes($car), "Joe's set of posessions is 
encapsulated");

These tests perhaps illustrate the level to which I've made them similar;

is($car->get_owner(0),  $joe, "Refs can look like arrays");
ok($car->owner_includes($joe), "Refs can look like encapsulated sets");
eval { $car->owner->includes($joe) };
ok($@, "Refs cannot behave like real Sets");

To make the last test work would need associations in the object core, I 
think.
-- 
Sam Vilain, [EMAIL PROTECTED]

Whatever you do will be insignificant, but it is very important that
you do it.
 -- Mahatma Gandhi 

Reply via email to