Nathan,
On Sep 21, 2005, at 9:02 AM, Nathan Gray wrote:
On Tue, Sep 20, 2005 at 08:16:23PM -0400, Stevan Little wrote:
http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel2.0/docs/
p6_role_model.jpg
I am planning on making Roles self-bootstrapping, so the class(Role)
will actually be the first Role in the system. From there, Class will
do Role, and Role will do Role. This also means that all the
instances of Class will also do Role, which means that classes
automatically can also be used as Roles.
Thanks for the pictures, Stevan.
So every time a class does a new role, a new instance of the class is
created as the role.
Nope. The Role interface is (for the most part) a subset of the Class
interface, well at least the important bits are. So I manually
bootstrap the role(Role) into the class(Class), this then means that
Class.does(Role). THis means that all instances of Class (all the
user defined classes) themselves also do Role. This means that all
Classes then become interchangeable with Roles. No new class or role
instances need to be created, it is all inherited behavior from the
class(Class).
If a class does three roles, there will be three role instances of
the class, as well as the class' own instance of itself, and a user
instance.
No, Roles are disposed of once class composition is complete. Part of
the class composition process will be to consume any Roles which the
class does. THe consumption process takes all the methods and
attributes from the Role and actually adds them into the class. After
that, the role can essentially be discarded (unless another class
uses that same role).
When a method is called on the user instance, it asks the class
instance
if it can do the method, and the class instance looks at the
methods in
the class, and then at the methods in each role, and dispatches to the
appropriate method definition.
The dispatch is always in the class since role methods are consumed
into the class.
A role can be "done" by several classes at once, because a new
instance
is created for each class, specific to the class.
Methods defined in a class are not clobbered by methods defined in a
role. Rather, methods in a role are only catalogued by the class
instance if it does not already have a method definition for that
name.
The order that a class does roles is significant, because if two roles
define the same method, only the first one is catalogued by the class
instance.
Class methods are used first, if the class method is not there, then
the Role method is used. If there is a conflict with Role methods,
neither Role method is used. By making all conflicts behave this way,
we make Role order not-significant. Also If two Role methods
conflict, the class consuming the roles must implement that method,
otherwise it is a fatal error.
Stevan
-kolibrie