Your SlideShare is downloading. ×
0
S.Ducasse 1
Metaclasses in 7 Steps
Classes are objects too...
Classes are instances of other classes
...
One model applied...
S.Ducasse 2
Metaclasses in 7 points
Every object is an instance of a class
Every class eventually inherits from Object
Eve...
S.Ducasse 3
Metaclasses in 7 points
Every object is an instance of a class
Every class eventually inherits from Object
Eve...
S.Ducasse 4
1. Every object is an instance of a class
S.Ducasse 5
Metaclasses in 7 points
Every object is an instance of a class
Every class eventually inherits from
Object
Eve...
S.Ducasse 6
2. Every class inherits from Object
Every object is-an Object
The class of every object
ultimately inherits fr...
S.Ducasse 7
The Meaning of is-a
When an object receives a message, the method is
looked up in the method dictionary of its...
S.Ducasse 8
Responsibilities of Object
Object
represents the common object behavior
error-handling, halting …
all classes ...
S.Ducasse 9
Metaclasses in 7 points
Every object is an instance of a class
Every class eventually inherits from Object
Eve...
S.Ducasse 10
3. Every class is an instance of a metaclass
Classes are objects too!
Every class X is the unique instance of...
S.Ducasse 11
Metaclasses are implicit
There are no explicit metaclasses
Metaclasses are created implicitly when classes ar...
S.Ducasse 12
Metaclasses by Example
Square allSubclassesSquare allSubclasses
Snake allSubclassesSnake allSubclasses
Snake ...
S.Ducasse 13
Metaclasses in 7 points
Every object is an instance of a class
Every class eventually inherits from Object
Ev...
S.Ducasse 14
4.The metaclass hierarchy parallels the
class hierarchy
S.Ducasse 15
Uniformity between Classes and Objects
Classes are objects too, so …
Everything that holds for objects holds ...
S.Ducasse 16
About the Buttons
S.Ducasse 17
Metaclasses in 7 points
Every object is an instance of a class
Every class eventually inherits from Object
Ev...
S.Ducasse 18
5. Every metaclass inherits from Class and
Behavior
18
Every class is-a Class =
The metaclass of every
class ...
S.Ducasse 19
Where is new defined?
S.Ducasse 20
Responsibilities of Behavior
Behavior
Minimum state necessary for objects that have instances.
Basic interfac...
S.Ducasse 21
Responsibilities of ClassDescription
ClassDescription
adds a number of facilities to basic Behavior:
named in...
S.Ducasse 22
Responsibilities of Class
Class
represents the common behavior of all classes
name, compilation, method stori...
S.Ducasse 23
Metaclasses in 7 points
Every object is an instance of a class
Every class eventually inherits from Object
Ev...
S.Ducasse 24
6. Every metaclass is an instance of
Metaclass
S.Ducasse 25
Metaclass Responsibilities
Metaclass
Represents common metaclass Behavior
instance creation (subclassOf:)
cre...
S.Ducasse 26
Metaclasses in 7 points
Every object is an instance of a class
Every class eventually inherits from Object
Ev...
S.Ducasse 27
7.The metaclass of Metaclass is an instance
of Metaclass
S.Ducasse 28
Navigating the metaclass hierarchy
MetaclassHierarchyTest>>testHierarchyMetaclassHierarchyTest>>testHierarchy...
Upcoming SlideShare
Loading in...5
×

Stoop 400 o-metaclassonly

465

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
465
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Stoop 400 o-metaclassonly"

  1. 1. S.Ducasse 1 Metaclasses in 7 Steps Classes are objects too... Classes are instances of other classes ... One model applied twice
  2. 2. S.Ducasse 2 Metaclasses in 7 points Every object is an instance of a class Every class eventually inherits from Object Every class is an instance of a metaclass The metaclass hierarchy parallels the class hierarchy Every metaclass inherits from Class and Behavior Every metaclass is an instance of Metaclass The metaclass of Metaclass is an instance of Metaclass Adapted from Goldberg & Robson, Smalltalk-80 — The Language
  3. 3. S.Ducasse 3 Metaclasses in 7 points Every object is an instance of a class Every class eventually inherits from Object Every class is an instance of a metaclass The metaclass hierarchy parallels the class hierarchy Every metaclass inherits from Class and Behavior Every metaclass is an instance of Metaclass The metaclass of Metaclass is an instance of Metaclass
  4. 4. S.Ducasse 4 1. Every object is an instance of a class
  5. 5. S.Ducasse 5 Metaclasses in 7 points Every object is an instance of a class Every class eventually inherits from Object Every class is an instance of a metaclass The metaclass hierarchy parallels the class hierarchy Every metaclass inherits from Class and Behavior Every metaclass is an instance of Metaclass The metaclass of Metaclass is an instance of Metaclass
  6. 6. S.Ducasse 6 2. Every class inherits from Object Every object is-an Object The class of every object ultimately inherits from Object
  7. 7. S.Ducasse 7 The Meaning of is-a When an object receives a message, the method is looked up in the method dictionary of its class, and, if necessary, its superclasses, up to Object
  8. 8. S.Ducasse 8 Responsibilities of Object Object represents the common object behavior error-handling, halting … all classes should inherit ultimately from Object
  9. 9. S.Ducasse 9 Metaclasses in 7 points Every object is an instance of a class Every class eventually inherits from Object Every class is an instance of a metaclass The metaclass hierarchy parallels the class hierarchy Every metaclass inherits from Class and Behavior Every metaclass is an instance of Metaclass The metaclass of Metaclass is an instance of Metaclass
  10. 10. S.Ducasse 10 3. Every class is an instance of a metaclass Classes are objects too! Every class X is the unique instance of its metaclass, called X class
  11. 11. S.Ducasse 11 Metaclasses are implicit There are no explicit metaclasses Metaclasses are created implicitly when classes are created No sharing of metaclasses (unique metaclass per class)
  12. 12. S.Ducasse 12 Metaclasses by Example Square allSubclassesSquare allSubclasses Snake allSubclassesSnake allSubclasses Snake allInstancesSnake allInstances Snake instVarNamesSnake instVarNames Snake back: 5Snake back: 5 Snake selectorsSnake selectors Snake canUnderstand: #newSnake canUnderstand: #new Snake canUnderstand: #setBack:Snake canUnderstand: #setBack:
  13. 13. S.Ducasse 13 Metaclasses in 7 points Every object is an instance of a class Every class eventually inherits from Object Every class is an instance of a metaclass The metaclass hierarchy parallels the class hierarchy Every metaclass inherits from Class and Behavior Every metaclass is an instance of Metaclass The metaclass of Metaclass is an instance of Metaclass
  14. 14. S.Ducasse 14 4.The metaclass hierarchy parallels the class hierarchy
  15. 15. S.Ducasse 15 Uniformity between Classes and Objects Classes are objects too, so … Everything that holds for objects holds for classes as well Same method lookup strategy Look up in the method dictionary of the metaclass
  16. 16. S.Ducasse 16 About the Buttons
  17. 17. S.Ducasse 17 Metaclasses in 7 points Every object is an instance of a class Every class eventually inherits from Object Every class is an instance of a metaclass The metaclass hierarchy parallels the class hierarchy Every metaclass inherits from Class and Behavior Every metaclass is an instance of Metaclass The metaclass of Metaclass is an instance of Metaclass
  18. 18. S.Ducasse 18 5. Every metaclass inherits from Class and Behavior 18 Every class is-a Class = The metaclass of every class inherits from Class
  19. 19. S.Ducasse 19 Where is new defined?
  20. 20. S.Ducasse 20 Responsibilities of Behavior Behavior Minimum state necessary for objects that have instances. Basic interface to the compiler. State: class hierarchy link, method dictionary, description of instances (representation and number) Methods: creating a method dictionary, compiling method instance creation (new, basicNew, new:, basicNew:) class hierarchy manipulation (superclass:, addSubclass:) accessing (selectors, allSelectors, compiledMethodAt: ) accessing instances and variables (allInstances, instVarNames) accessing class hierarchy (superclass, subclasses) testing (hasMethods, includesSelector, canUnderstand:, inheritsFrom:, isVariable)
  21. 21. S.Ducasse 21 Responsibilities of ClassDescription ClassDescription adds a number of facilities to basic Behavior: named instance variables category organization for methods the notion of a name (abstract) maintenance of Change sets and logging changes most of the mechanisms needed for fileOut ClassDescription is an abstract class: its facilities are intended for inheritance by the two subclasses, Class and Metaclass.
  22. 22. S.Ducasse 22 Responsibilities of Class Class represents the common behavior of all classes name, compilation, method storing, instance variables … representation for classVariable names and shared pool variables (addClassVarName:, addSharedPool:, initialize) Class inherits from Object because Class is an Object Class knows how to create instances, so all metaclasses should inherit ultimately from Class
  23. 23. S.Ducasse 23 Metaclasses in 7 points Every object is an instance of a class Every class eventually inherits from Object Every class is an instance of a metaclass The metaclass hierarchy parallels the class hierarchy Every metaclass inherits from Class and Behavior Every metaclass is an instance of Metaclass The metaclass of Metaclass is an instance of Metaclass
  24. 24. S.Ducasse 24 6. Every metaclass is an instance of Metaclass
  25. 25. S.Ducasse 25 Metaclass Responsibilities Metaclass Represents common metaclass Behavior instance creation (subclassOf:) creating initialized instances of the metaclass’s sole instance initialization of class variables metaclass instance protocol (name:inEnvironment:subclassOf:....) method compilation (different semantics can be introduced) class information (inheritance link, instance variable, ...)
  26. 26. S.Ducasse 26 Metaclasses in 7 points Every object is an instance of a class Every class eventually inherits from Object Every class is an instance of a metaclass The metaclass hierarchy parallels the class hierarchy Every metaclass inherits from Class and Behavior Every metaclass is an instance of Metaclass The metaclass of Metaclass is an instance of Metaclass
  27. 27. S.Ducasse 27 7.The metaclass of Metaclass is an instance of Metaclass
  28. 28. S.Ducasse 28 Navigating the metaclass hierarchy MetaclassHierarchyTest>>testHierarchyMetaclassHierarchyTest>>testHierarchy "The class hierarchy""The class hierarchy" self assert: Snake superclass = Square.self assert: Snake superclass = Square. self assert: Square superclass = Object.self assert: Square superclass = Object. self assert: Object superclass superclass = nil. "skip ProtoObject"self assert: Object superclass superclass = nil. "skip ProtoObject" "The parallel metaclass hierarchy""The parallel metaclass hierarchy" self assert: Snake class name = 'Snake class'.self assert: Snake class name = 'Snake class'. self assert: Snake class superclass = Square class.self assert: Snake class superclass = Square class. self assert: Square class superclass = Object class.self assert: Square class superclass = Object class. self assert: Object class superclass superclass = Class.self assert: Object class superclass superclass = Class. self assert: Class superclass = ClassDescription.self assert: Class superclass = ClassDescription. self assert: ClassDescription superclass = Behavior.self assert: ClassDescription superclass = Behavior. self assert: Behavior superclass = Object.self assert: Behavior superclass = Object. "The Metaclass hierarchy""The Metaclass hierarchy" self assert: Snake class class = Metaclass.self assert: Snake class class = Metaclass. self assert: Square class class = Metaclass.self assert: Square class class = Metaclass. self assert: Object class class = Metaclass.self assert: Object class class = Metaclass. self assert: Class class class = Metaclass.self assert: Class class class = Metaclass. self assert: ClassDescription class class = Metaclass.self assert: ClassDescription class class = Metaclass. self assert: Behavior class class = Metaclass.self assert: Behavior class class = Metaclass. self assert: Metaclass superclass = ClassDescription.self assert: Metaclass superclass = ClassDescription. "The fixpoint""The fixpoint" self assert: Metaclass class class = Metaclass.self assert: Metaclass class class = Metaclass.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×