SlideShare a Scribd company logo
S. Ducasse 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 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 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 4
Upward Compatible
• aB i-foo => no error
Meta A
c-bar
A
i-foo
A>>i-foo
^ self class c-bar
Meta B
B
inherits from
instance of
?
S. Ducasse 5
Downward Compatible
• B c-bar => no error
Meta A
c-bar
A
i-bar
Meta A>>c-bar
^ self new i-bar
Meta B
B
inherits from
instance of
?
S. Ducasse 6
Smalltalk-80
• Implicit
• Safe
• Limited reuse
Meta A>>c-foo
^ self new i-bar Meta A
c-bar
c-foo
A
i-foo
i-bar
Meta B
B
A>>i-foo
^ self class c-bar
inherits from
instance of
S. Ducasse 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 8
Our approach: traits
• Implicit metaclasses
• But traits to compose classes
• Reuse of traits
A B
inherits from
instance of
Meta A
Class
Property2
Meta B
Class
Property1
S. Ducasse 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
radius
radius:
center
center:
TCircle
area
bounds
diameter
hash
S. Ducasse 10
How are Traits Used?
• Traits are the behavioral building blocks of
classes
• Class = Superclass + state + traits + glue
methods
• Class methods take precedence over trait
methods
Object
ColoredCircle
TColor
TCircle
S. Ducasse 11
Conflicts Explicitly Resolved
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
ColoredCircle
TColor
hash
TCircle
hash
hash
hash -> circleHash
hash -> colorHash
S. Ducasse 12
Hierarchies Revisited...
Boolean
False
True
False class
True class
TSingleton
Boolean class
TAbstract
TSingleton
Behavior
TCreator
new
basicNew
Boolean class
TAbstract
new
False class
TSingleton
new
default
reset
basicNew
uniqueInstance
uniqueInstance:
S. Ducasse 13
Metalevel Reengineering
TRememberInstances
new
rememberInstance
instances
reset
rememberedInstances
rememberedInstances:
TInstantiator
new
TAllocate
basicNew
TInitInstantiator
new initialize
TAbstract
new
TFinal
subclass:
TSharedInstance
reset
sharedInstance
directSharedInstance
directSharedInstance:
TDefault
TSingleton
new
sharedNew ! new
default !
sharedInstance uniqueInstance !
sharedInstance
nonRememberingNew ! new
is composed from
TSingleton
new
Trait
m1 ! m2
creates an alias
m2 referring to m1
Legend
S. Ducasse 14
Traits Implementation
• Available in Squeak 3.7
• Bootstrapping the kernel
PureBehavior
BehaviorTraitBehavior
Class
Description
Class Metaclass
Trait
Description
Trait
S. Ducasse 15
Conclusion
• Uniform
• Traits are instance and class level!
• Explicit Composition
• Reuse but Safe

More Related Content

PPSX
Learn java objects inheritance-overriding-polymorphism
PPTX
Inheritance in JAVA PPT
PPTX
Java(inheritance)
PPT
04 inheritance
PPTX
inheritance
PPT
Java inheritance
PPTX
Java Inheritance | Java Course
Learn java objects inheritance-overriding-polymorphism
Inheritance in JAVA PPT
Java(inheritance)
04 inheritance
inheritance
Java inheritance
Java Inheritance | Java Course

What's hot (20)

PDF
javainheritance
PPTX
Inheritance ppt
PDF
Equivalence Class Testing [8] - Software Testing Techniques (CIS640)
PPT
inheritance
PPS
Dacj 2-1 a
PPTX
Inheritance and its types In Java
PPT
04 inheritance
PDF
java-06inheritance
PPTX
Inheritance in oops
PPTX
Chapter 9 java
PDF
itft-Inheritance in java
PPTX
27csharp
PPTX
Chapter 05 polymorphism extra
PPTX
B.sc CSIT 2nd semester C++ Unit5
PPTX
Inheritance and Polymorphism
PPTX
Inheritance In Java
PPTX
Mca 2nd sem u-3 inheritance
PPT
Java: Inheritance
PPTX
.NET F# Abstract class interface
javainheritance
Inheritance ppt
Equivalence Class Testing [8] - Software Testing Techniques (CIS640)
inheritance
Dacj 2-1 a
Inheritance and its types In Java
04 inheritance
java-06inheritance
Inheritance in oops
Chapter 9 java
itft-Inheritance in java
27csharp
Chapter 05 polymorphism extra
B.sc CSIT 2nd semester C++ Unit5
Inheritance and Polymorphism
Inheritance In Java
Mca 2nd sem u-3 inheritance
Java: Inheritance
.NET F# Abstract class interface
Ad

Similar to Uniform and Safe Metaclass Composition (20)

PPT
Stoop 400 o-metaclassonly
PPT
Stoop metaclasses
PPT
Stoop 304-metaclasses
PPT
Stoop 421-design heuristics
PPT
Stoop 305-reflective programming5
PPT
Stoop 423-some designpatterns
PPTX
Design pattern
PPT
7 - OOP - OO Concepts
PPT
Stoop ed-subtyping subclassing
PPT
09 metaclasses
KEY
Traits composition
PPT
Polymorphism
PPT
Stoop 414-smalltalk elementsofdesign
PPT
Stoop ed-class forreuse
PPT
Stoop 422-naming idioms
PDF
Stateful Traits
PPT
14 Defining classes
PDF
Object oriented programming interview questions
PPTX
Object Oriented Principles
Stoop 400 o-metaclassonly
Stoop metaclasses
Stoop 304-metaclasses
Stoop 421-design heuristics
Stoop 305-reflective programming5
Stoop 423-some designpatterns
Design pattern
7 - OOP - OO Concepts
Stoop ed-subtyping subclassing
09 metaclasses
Traits composition
Polymorphism
Stoop 414-smalltalk elementsofdesign
Stoop ed-class forreuse
Stoop 422-naming idioms
Stateful Traits
14 Defining classes
Object oriented programming interview questions
Object Oriented Principles
Ad

More from ESUG (20)

PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
PDF
Directing Generative AI for Pharo Documentation
PDF
Even Lighter Than Lightweiht: Augmenting Type Inference with Primitive Heuris...
PDF
Composing and Performing Electronic Music on-the-Fly with Pharo and Coypu
PDF
Gamifying Agent-Based Models in Cormas: Towards the Playable Architecture for...
PDF
Analysing Python Machine Learning Notebooks with Moose
PDF
FASTTypeScript metamodel generation using FAST traits and TreeSitter project
PDF
Migrating Katalon Studio Tests to Playwright with Model Driven Engineering
PDF
Package-Aware Approach for Repository-Level Code Completion in Pharo
PDF
Evaluating Benchmark Quality: a Mutation-Testing- Based Methodology
PDF
An Analysis of Inline Method Refactoring
PDF
Identification of unnecessary object allocations using static escape analysis
PDF
Control flow-sensitive optimizations In the Druid Meta-Compiler
PDF
Clean Blocks (IWST 2025, Gdansk, Poland)
PDF
Encoding for Objects Matters (IWST 2025)
PDF
Challenges of Transpiling Smalltalk to JavaScript
PDF
Immersive experiences: what Pharo users do!
PDF
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
PDF
Cavrois - an Organic Window Management (ESUG 2025)
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
Micromaid: A simple Mermaid-like chart generator for Pharo
Directing Generative AI for Pharo Documentation
Even Lighter Than Lightweiht: Augmenting Type Inference with Primitive Heuris...
Composing and Performing Electronic Music on-the-Fly with Pharo and Coypu
Gamifying Agent-Based Models in Cormas: Towards the Playable Architecture for...
Analysing Python Machine Learning Notebooks with Moose
FASTTypeScript metamodel generation using FAST traits and TreeSitter project
Migrating Katalon Studio Tests to Playwright with Model Driven Engineering
Package-Aware Approach for Repository-Level Code Completion in Pharo
Evaluating Benchmark Quality: a Mutation-Testing- Based Methodology
An Analysis of Inline Method Refactoring
Identification of unnecessary object allocations using static escape analysis
Control flow-sensitive optimizations In the Druid Meta-Compiler
Clean Blocks (IWST 2025, Gdansk, Poland)
Encoding for Objects Matters (IWST 2025)
Challenges of Transpiling Smalltalk to JavaScript
Immersive experiences: what Pharo users do!
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
Cavrois - an Organic Window Management (ESUG 2025)

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Encapsulation theory and applications.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Machine Learning_overview_presentation.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Electronic commerce courselecture one. Pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Approach and Philosophy of On baking technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Empathic Computing: Creating Shared Understanding
PDF
Machine learning based COVID-19 study performance prediction
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
sap open course for s4hana steps from ECC to s4
Encapsulation theory and applications.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Machine Learning_overview_presentation.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Electronic commerce courselecture one. Pdf
Assigned Numbers - 2025 - Bluetooth® Document
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Unlocking AI with Model Context Protocol (MCP)
Approach and Philosophy of On baking technology
20250228 LYD VKU AI Blended-Learning.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Programs and apps: productivity, graphics, security and other tools
Empathic Computing: Creating Shared Understanding
Machine learning based COVID-19 study performance prediction
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

Uniform and Safe Metaclass Composition

  • 1. S. Ducasse 1 Uniform and Safe Metaclass Composition Stéphane Ducasse, Nathanael Schaerli and Roel Wuyts ducasse@iam.unibe.ch http://www.iam.unibe.ch/~ducasse/
  • 2. S. Ducasse 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
  • 3. S. Ducasse 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
  • 4. S. Ducasse 4 Upward Compatible • aB i-foo => no error Meta A c-bar A i-foo A>>i-foo ^ self class c-bar Meta B B inherits from instance of ?
  • 5. S. Ducasse 5 Downward Compatible • B c-bar => no error Meta A c-bar A i-bar Meta A>>c-bar ^ self new i-bar Meta B B inherits from instance of ?
  • 6. S. Ducasse 6 Smalltalk-80 • Implicit • Safe • Limited reuse Meta A>>c-foo ^ self new i-bar Meta A c-bar c-foo A i-foo i-bar Meta B B A>>i-foo ^ self class c-bar inherits from instance of
  • 7. S. Ducasse 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
  • 8. S. Ducasse 8 Our approach: traits • Implicit metaclasses • But traits to compose classes • Reuse of traits A B inherits from instance of Meta A Class Property2 Meta B Class Property1
  • 9. S. Ducasse 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 radius radius: center center: TCircle area bounds diameter hash
  • 10. S. Ducasse 10 How are Traits Used? • Traits are the behavioral building blocks of classes • Class = Superclass + state + traits + glue methods • Class methods take precedence over trait methods Object ColoredCircle TColor TCircle
  • 11. S. Ducasse 11 Conflicts Explicitly Resolved 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 ColoredCircle TColor hash TCircle hash hash hash -> circleHash hash -> colorHash
  • 12. S. Ducasse 12 Hierarchies Revisited... Boolean False True False class True class TSingleton Boolean class TAbstract TSingleton Behavior TCreator new basicNew Boolean class TAbstract new False class TSingleton new default reset basicNew uniqueInstance uniqueInstance:
  • 13. S. Ducasse 13 Metalevel Reengineering TRememberInstances new rememberInstance instances reset rememberedInstances rememberedInstances: TInstantiator new TAllocate basicNew TInitInstantiator new initialize TAbstract new TFinal subclass: TSharedInstance reset sharedInstance directSharedInstance directSharedInstance: TDefault TSingleton new sharedNew ! new default ! sharedInstance uniqueInstance ! sharedInstance nonRememberingNew ! new is composed from TSingleton new Trait m1 ! m2 creates an alias m2 referring to m1 Legend
  • 14. S. Ducasse 14 Traits Implementation • Available in Squeak 3.7 • Bootstrapping the kernel PureBehavior BehaviorTraitBehavior Class Description Class Metaclass Trait Description Trait
  • 15. S. Ducasse 15 Conclusion • Uniform • Traits are instance and class level! • Explicit Composition • Reuse but Safe