+ All Categories
Home > Technology > 2013 lecture-02-model

2013 lecture-02-model

Date post: 11-May-2015
Category:
Upload: pharo
View: 209 times
Download: 0 times
Share this document with a friend
Description:
An introduction of the Pharo execution model. Pharo is a new dynamically typed language. It is inspired from Smalltalk and it is elegant, simple and powerful. http://www.pharo.org
Popular Tags:
31
A Little Journey in the Pharo Object Model Stéphane Ducasse http://www.pharo.org
Transcript
Page 1: 2013 lecture-02-model

A Little Journey in the Pharo Object ModelStéphane Ducassehttp://www.pharo.org

Page 2: 2013 lecture-02-model

A pure and minimal object model

Less is more!

Page 3: 2013 lecture-02-model

No constructors, no static methods, no operators

No type declaration, no primitive types,

No interfaces, no need for factory

No packages/private/protected modifiers

No parametrized types

No boxing/unboxing

Still powerful

Page 4: 2013 lecture-02-model

Everything is an object

Page 5: 2013 lecture-02-model

Objects are instances of Classes

Page 6: 2013 lecture-02-model

(10@200)

Objects are instances of Classes

Page 7: 2013 lecture-02-model

(10@200) class

Objects are instances of Classes

Page 8: 2013 lecture-02-model

(10@200) class

Point

Objects are instances of Classes

Page 9: 2013 lecture-02-model

Classes are objects too

Page 10: 2013 lecture-02-model

Point selectors

Classes are objects too

Page 11: 2013 lecture-02-model

Point selectors

> an IdentitySet(#eightNeighbors #+ #isZero #sortsBefore: #degrees #printOn: #sideOf: #fourNeighbors #hash #roundUpTo: #min: #min:max: #max #adaptToCollection:andSend: #quadrantOf: #crossProduct: #= #nearestPointOnLineFrom:to: #bitShiftPoint: #* #guarded #insideTriangle:with:with: #grid: #truncateTo: #y #setR:degrees: #normal

Classes are objects too

Page 12: 2013 lecture-02-model

Point instVarNames

Classes are objects too

Page 13: 2013 lecture-02-model

Point instVarNames

>#('x' 'y')

Classes are objects too

Page 14: 2013 lecture-02-model

Methods are public

Page 15: 2013 lecture-02-model

Methods are all late-bound

Page 16: 2013 lecture-02-model

Instance variables are protected

Page 17: 2013 lecture-02-model

Single Inheritance

Page 18: 2013 lecture-02-model

Object subclass: #Point

instanceVariableNames: 'x y'

classVariableNames: ''

category: 'Graphics-Primitives'

Single Inheritance

Page 19: 2013 lecture-02-model

Messages + Objects

Page 20: 2013 lecture-02-model

Object

Node

accept:

name

sendt:

node1

msg

The key to everything

Page 21: 2013 lecture-02-model

Classes are objects too

Page 22: 2013 lecture-02-model

Point class

Classes are objects too

Page 23: 2013 lecture-02-model

Point class

>Point class

Classes are objects too

Page 24: 2013 lecture-02-model

Point class

>Point class

“Point class” is an anonymous class with only one instance: Point

Classes are objects too

Page 25: 2013 lecture-02-model

Class Parallel Inheritance Node class

newwithName: aString

instance of

Node

nameaccept: aPacketsend: aPacket

Workstation

originate: aPacketaccept: aPacket

aWorkstation (BigMac)

Workstation

class

instance of

Page 26: 2013 lecture-02-model

Lookup and Class Methods

Page 27: 2013 lecture-02-model

About the Buttons

Page 28: 2013 lecture-02-model

Class methods are plain late bound methods as any methods!

Page 29: 2013 lecture-02-model

Package extensions

A method can be defined in a class that is packaged in another package!Powerful to build layers

Page 30: 2013 lecture-02-model

Defined in the Dice packageInteger>>D20 ^ self D: 20

Integer>>D: anInteger | h | h := DiceHandle new self timesRepeat: [h addDice: (Dice faces: anInteger)]. ^ h

2 D20: two dice of 20 faces

Page 31: 2013 lecture-02-model

SummaryEverything is an object

Single inheritance, public methods, protected attributes

One single model

Classes are simply objects too

A class is instance of another class

One unique method lookup, look in the class of the receiver


Recommended