On Fri, Dec 12, 2003 at 04:23:02AM -0700, Luke Palmer wrote:
: So I'm seeing a lot of inconsistent OO-vocabulary around here, and it
: makes things pretty hard to understand.
Agreed.
: So here's how Perl 6 is using said inconsistent terms, AFAIK:
:
: - attribute
: A concrete data member of a class. Used with C<has>.
Declared with C<has> is a little more precise.
: - property
: An out-of-band sticky note to be placed on a single object.
: Used with C<but>.
Maybe "applied with"?
: - trait
: A compile time sticky note to be placed on a wide variety of things.
: Used with C<is>.
Fine. (Though I like to hyphenate "compile-time" when it's an adjective,
and not when it's a noun. Same for "run-time", just to be consistent.)
: - role
: A collection of methods to be incorporated into a class sans
A role can also supply one or more attributes.
: inheritance (and maybe some other stuff, too). Used with C<does>.
Here it gets a little fuzzier. A role can be applied to a class
at compile time via "does", or to an object at run time via "but".
A property is a simple kind of role that supplies a single attribute.
The type of a property is identical to its role name. Roles can have
subtypes that function as enums when the subtypes are constrained to a
single value. You can use one of these subtypes without specifically
implying the role name. So saying
$bar but Red
might give you a value with the property Color. You can write the corresponding
boolean test using the smart match operator:
$bar ~~ Red
and it (smartly) picks out the Color property to compare with, provided
it's unambiguous. You can use that syntax to compare against any
subtype or junction of subtypes:
$bar ~~ Redish&Whiteish # pinkish
: So for example:
:
: class Dog
: does Boolean # role
: is extended # trait
: is Mammal # [1]
: {
: has $.tail; # attribute
: has @.legs; # attribute
: }
:
: my $fido = Dog.new
: but false; # property
:
: Hope that clears things up.
Yes, it does.
: Luke
:
: [1] This is a base class, which is an overloaded use of C<is>. Though,
: upon A12 release, we'll probably find out that it's not overloaded but
: instead, elegantly unified, somehow.
If not, it'll be easy to turn it into an "isa".
Larry