S.Ducasse 1 Metaclasses in 7 Steps Classes are objects too... Classes are instances of other classes... One model applied twice.

Slides:



Advertisements
Similar presentations
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz.
Advertisements

Object-Oriented Programming
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
Stéphane Ducasse 1 Design Points - Subclassing vs Subtyping Stéphane Ducasse
Stéphane Ducasse«ChapterNr».1 Selected Design Patterns Design Patterns are recurrent solutions to design problems They are pros and cons We already saw:
Principles of Object-Oriented Software Development The language Smalltalk.
Object-Oriented Databases v OO systems associated with – graphical user interface (GUI) – powerful modeling techniques – advanced data management capabilities.
7. Understanding Classes and Metaclasses. © Oscar Nierstrasz ST — Understanding Classes and Metaclasses 7.2 Roadmap  Metaclasses in 7 points  Indexed.
Stéphane Ducasse9.1 Inheritance Semantics and Lookup.
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Summer Semester 2006.
Principles of Object-Oriented Software Development Object-oriented programming languages.
13. Traits. Selected literature  Cook. Interfaces and Specifications for the Smalltalk-80 Collection Classes. OOPSLA 1992  Taivalsaari. On the Notion.
Basic OOP Concepts and Terms
Stéphane Ducasse6.1 Essential Concepts Why OO? What is OO? What are the benefits? What are the KEY concepts? Basis for all the lectures.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
1 Introduction to CS Agenda Syllabus Schedule Lecture: the management of complexity.
Object-Oriented Databases
10. Reflection. © Oscar Nierstrasz ST — Reflection 10.2 Roadmap  What is reflection?  Object meta-operations  Class meta-operations  Method meta-operations.
9. Understanding Classes and Metaclasses. Birds-eye view © Oscar Nierstrasz ST — Introduction 1.2 Reify your metamodel — A fully reflective system models.
10. Reflection. © Oscar Nierstrasz ST — Reflection 10.2 Roadmap  What is reflection?  Object meta-operations  Class meta-operations  Method meta-operations.
Object-oriented programming and design 1 Smalltalk in a Nutshell Objects & classes Messages & methods Inheritance & metaclasses.
Stéphane Ducasse«ChapterNr».1 Advanced Classes Indexed Classes Classes as Objects Class Instance Variables and Methods Class Variables Pool Dictionaries.
Inheritance Review/Recap. ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the.
Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
CS 403 – Programming Languages Class 25 November 28, 2000.
CS 598 Scripting Languages Design and Implementation 7. Smalltalk 80.
S.Ducasse Stéphane Ducasse 1 Classes and Metaclasses - an Analysis.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
S.Ducasse Stéphane Ducasse 1 Design Heuristics.
Inheritance Dwight Deugo Nesa Matic
Chapter 8 - Additional Inheritance Concepts and Techniques1 Chapter 8 Additional Inheritance Concepts and Techniques.
Basic OOP Concepts and Terms. In this class, we will cover: Objects and examples of different object types Classes and how they relate to objects Object.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Inheritance Semantics and Method Lookup.
Lecture 12 March 16, The Scope of a Variable What if there are two variables with the same name? –A local or block-local variable can have the same.
ITEC 3220A Using and Designing Database Systems Instructor: Prof Z. Yang Course Website: 3220a.htm
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
CSC 131 Fall 2006 Lecture # 6 Object-Oriented Concepts.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Stéphane Ducasse 1 Singleton.
Object-Oriented Programming Chapter Chapter
S.Ducasse 1 7. Understanding Metaclasses. S.Ducasse 2 Roadmap Metaclasses in 7 points Indexed Classes Class Instance Variables Class Variables Pool Dictionaries.
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
S.Ducasse Stéphane Ducasse 1 Essential OO Concepts Stéphane Ducasse.
Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance  Problems with implementation inheritance: Encapsulation Fragile Base Class.
Stéphane Ducasse 1 Some Advanced Points on Classes.
1 Advanced Object Oriented Systems (CM0318) Lecture 8 (Last updated 15th February 2002)
Stéphane Ducasse 1 Some Points on Classes.
S.Ducasse Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Smalltalk in a Nutshell.
Stéphane Ducasse 1 Abstract Classes.
S.Ducasse Stéphane Ducasse 1 Some Advanced Points on Classes.
ISBN Chapter 12 Support for Object-Oriented Programming.
Administrative Issues Lecture 22 – Prolog (III), Fall 2007 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li, HW3 (due at March 18 th ) Essay.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
1 Case Study: Meta Classes  Class representation in memory  Class variables and class methods  Meta Classes  3 Level System  4 Level System  5 Level.
Smalltalk Meta-Programming Programming Languages HUJI 2010 Yardena Meymann.
Sections Inheritance and Abstract Classes
Types of Programming Languages
Section 11.1 Class Variables and Methods
The Procedure Abstraction Part V: Run-time Structures for OOLs
ITEC 3220A Using and Designing Database Systems
Introduction to Smalltalk
Basic OOP Concepts and Terms
Chapter 20 Object-Oriented Concepts and Principles
Presentation transcript:

S.Ducasse 1 Metaclasses in 7 Steps Classes are objects too... Classes are instances of other classes... One model applied twice

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

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

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 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

S.Ducasse 6 2. Every class inherits from Object Every object is-an Object The class of every object ultimately inherits from Object

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

S.Ducasse 8 Responsibilities of Object Object represents the common object behavior error-handling, halting … all classes should inherit ultimately from Object

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

S.Ducasse 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

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)

S.Ducasse 12 Metaclasses by Example Square allSubclasses Snake allSubclasses Snake allInstances Snake instVarNames Snake back: 5 Snake selectors Snake canUnderstand: #new Snake canUnderstand: #setBack:

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

S.Ducasse 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 for classes as well Same method lookup strategy Look up in the method dictionary of the metaclass

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 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

S.Ducasse Every metaclass inherits from Class and Behavior 18 Every class is-a Class = The metaclass of every class inherits from Class

S.Ducasse 19 Where is new defined?

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)

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.

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

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

S.Ducasse Every metaclass is an instance of Metaclass

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,...)

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

S.Ducasse The metaclass of Metaclass is an instance of Metaclass

S.Ducasse 28 Navigating the metaclass hierarchy MetaclassHierarchyTest>>testHierarchy "The class hierarchy" self assert: Snake superclass = Square. self assert: Square superclass = Object. self assert: Object superclass superclass = nil. "skip ProtoObject" "The parallel metaclass hierarchy" self assert: Snake class name = 'Snake class'. self assert: Snake class superclass = Square class. self assert: Square class superclass = Object class. self assert: Object class superclass superclass = Class. self assert: Class superclass = ClassDescription. self assert: ClassDescription superclass = Behavior. self assert: Behavior superclass = Object. "The Metaclass hierarchy" self assert: Snake class class = Metaclass. self assert: Square class class = Metaclass. self assert: Object class class = Metaclass. self assert: Class class class = Metaclass. self assert: ClassDescription class class = Metaclass. self assert: Behavior class class = Metaclass. self assert: Metaclass superclass = ClassDescription. "The fixpoint" self assert: Metaclass class class = Metaclass.