• Like


Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Uniform and Safe Metaclass Composition


Uniform and Safe Metaclass …

Uniform and Safe Metaclass
Composition. Stéphane Ducasse, Nathanael Schaerli and Roel Wuyts (ESUG 2004, Koethen)

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Uniform and Safe Metaclass Composition Stéphane Ducasse, Nathanael Schaerli and Roel Wuyts ducasse@iam.unibe.ch http://www.iam.unibe.ch/~ducasse/ S. Ducasse 1
  • 2. Why Metaclasses? • Classes are objects too • A class is an instance of a class called a metaclass • Uniformity: Classes are just objects • Control: Instance creation behavior • Reuse of class behavior S. Ducasse 2
  • 3. Implicit vs. Explicit • Implicit: programmer cannot specify the class • Safe but • Limited or no reuse • Explicit: • Composition metaclass is not safe • Ad-hoc composition mechanisms (for example: strings manipulation of neoclasstalk and dynamic class change) • Safe?: upward and downward compatible S. Ducasse 3
  • 4. Upward Compatible instance of Meta A Meta B inherits from c-bar ? A>>i-foo A B ^ self class c-bar i-foo • aB i-foo => no error S. Ducasse 4
  • 5. Downward Compatible Meta A Meta B Meta A>>c-bar c-bar ^ self new i-bar instance of A B inherits from i-bar ? • B c-bar => no error S. Ducasse 5
  • 6. Smalltalk-80 • Implicit • Safe • Limited reuse Meta A>>c-foo ^ self new i-bar Meta A Meta B c-bar c-foo A>>i-foo ^ self class c-bar A B i-foo instance of i-bar inherits from S. Ducasse 6
  • 7. Existing Solutions • Smalltalk-80 • Implicit, safe • But limited reuse • Clos • Explicit but help yourself! • NeoClasstalk • Dynamic class changes • Metaclass behavior specified as strings • MetaClasstalk • Double meta-layer with mixin composition S. Ducasse 7
  • 8. Our approach: traits • Implicit metaclasses • But traits to compose classes • Reuse of traits Meta A Meta B Class Class Property2 Property1 A B instance of inherits from S. Ducasse 8
  • 9. What are Traits? • Traits are parameterized behaviors • Traits provide a set of methods • Traits require a set of methods • Traits are purely behavioral • Traits do not specify any state TCircle area radius bounds radius: diameter center hash center: S. Ducasse 9
  • 10. How are Traits Used? • Traits are the behavioral building blocks of classes • Class = Superclass + state + traits + glue methods Object ColoredCircle TColor TCircle • Class methods take precedence over trait methods S. Ducasse 10
  • 11. Conflicts Explicitly Resolved ColoredCircle TCircle hash -> circleHash hash TColor hash -> colorHash I) Override the conflict with a glue method  Aliases provide access to the conflicting methods II) Avoid the conflict  Exclude the conflicting method from one trait S. Ducasse 11
  • 12. Hierarchies Revisited... Behavior Boolean class TCreator new False class basicNew TAbstract TSingleton Boolean class True class TAbstract TSingleton new Boolean False class TSingleton False new basicNew default uniqueInstance reset uniqueInstance: True S. Ducasse 12
  • 13. Metalevel Reengineering TAllocate basicNew TInstantiator TInitInstantiator new new initialize nonRememberingNew ! new sharedNew ! new TRememberInstances new rememberedInstances TAbstract TSharedInstance rememberInstance rememberedInstances: new reset directSharedInstance instances sharedInstance directSharedInstance: reset default ! sharedInstance uniqueInstance ! TFinal sharedInstance subclass: TDefault TSingleton new Legend TSingleton m1 ! m2 is composed from new creates an alias Trait m2 referring to m1 S. Ducasse 13
  • 14. Traits Implementation • Available in Squeak 3.7 • Bootstrapping the kernel PureBehavior TraitBehavior Behavior Trait Class Description Description Trait Class Metaclass S. Ducasse 14
  • 15. Conclusion • Uniform • Traits are instance and class level! • Explicit Composition • Reuse but Safe S. Ducasse 15