Date post: | 18-Jul-2015 |
Category: |
Technology |
Upload: | pharo |
View: | 75 times |
Download: | 3 times |
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
A Pure OO World
Only objects mouse, booleans, arrays, numbers, strings, windows, scrollbars, canvas, files, trees, compilers, sound, url, socket, fonts, text, collections, stack, shortcut, streams, …
& messages
Simple and Uniform
Everything in an object instance of a class
Classes are objects
Only message passing (method invocation)
Only one method lookup (virtual)
Packages contain classes and methods
Object Model
Instance variables are private to the object (instance-based)
ClassVariables are shared between subclasses
Instance variables are protected
Methods are public, virtual
Single Inheritance
Object subclass: #Point
instanceVariableNames: 'x y'
classVariableNames: ''
category: 'Graphics-Primitives'
Single Inheritance
Look for the message selector in the class of the receiver
if found return it
if not look in the superclass
Execute the message on the receiver
Sending a message
!
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
Instance creation
Just messages send to special objects that are classes
Morph new
Character cr
Rectangle origin: 0@0 corner: 100@200
Tomagashi withHunger: 10
Cheap factories :)
Parser>>parse: line
self sortedParsers
detect: [ :sub | (sub canParse: aLine)
ifTrue: [ ^ sub newFromLine: line ] ]
!
Parser>>sortedParsers
^ DocumentItem allSubclasses
sorted: [ :c1 :c2 | c1 priority < c2 priority ]
!
Point class
>Point class
!
“Point class” is an anonymous class (called a metaclass) with only one instance: the class Point
Classes are objects too
Class Parallel Inheritance Node class
newwithName: aString
instance of
Node
nameaccept: aPacketsend: aPacket
Workstation
originate: aPacketaccept: aPacket
aWorkstation (BigMac)
Workstation
class
instance of
Package extensions
A method can be defined in a class that is packaged in another package! Powerful to build layers
Defined in the Dice package Integer>>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
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
A package can contain methods defined on classes defined in other packages.