--- Sam Vilain <[EMAIL PROTECTED]> wrote:
> 
> 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");

How much of Association is just "tricky, sticky property"?

You'd like to declare the relationship between them, but this can be
really difficult (consider e.g., nethack, in which the things you can
"own" are constrained by weight/volume/knapsack).

So certainly you need to be able to add code to the equation.

Person::possess(o is Object)
{
  if (weight_of_my_stuff() + weight_of(o) > $self.weight_limit)
  {
    whine(...);
  }
  else
  {
    $self.stuff.push(o);
  }
}

In other cases, you don't care so much. So then it would be nice if you
could declare the relationship and have the accessor functions get
generated for you.



I work with a tool that provides just a little built in support for
this kind of thing:

When you create a relationship (using the "relate" command) between to
objects, you can do:

ccm relate -from $object_spec_1 
           -name $relationship_name 
           -to $object_spec_2

ccm unrelate [spec, as above]

ccm relate -show [partial or complete spec, as above: -f -t -n]

ccm query "is_<relationship_name>_of('$object_spec')"
ccm query "has_<relationship_name>('$object_spec')"

The relate database is pretty straightforward -- a three-column table.

The query part is supported by "magic" -- the query syntax parser knows
how to chop up is_XXX_of() and has_XXX() predicates to extract
relationship names.


I think that the Association concept can be implemented as a non-core
package. You'll declare Associations like classes, except that they'll
mostly be auto-generated. However, if you need to insert code (as
above) you can explicitly spell out your sub.

What would be nice would be a convention for
accessing/creating/querying/modifying them, so that whenever we see
"is_AssociationName_of(...)" (or whatever) we know that this is an
association.

=Austin

Reply via email to