Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of...

138
Classes Are Premature Optimization Justin Love http://pinboard.in/u:wondible/t:prototypal/ http://pinboard.in/u:wondible/t:oop/

Transcript of Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of...

Page 1: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Classes Are Premature Optimization

Justin Lovehttp://pinboard.in/u:wondible/t:prototypal/

http://pinboard.in/u:wondible/t:oop/

Page 3: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Outline

• OOP

• Classical

• Prototypal

• Performance

• Review

Page 4: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

OOP?

Page 5: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

class ____ { ...}

Page 6: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

object ____ { ...}

Page 7: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Class Oriented?

class ____ { ...}

Page 8: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

OOP-or-

COP?

Page 9: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

OOP

Page 10: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Those who do not remember history are condemned to repeat it.

George Santayana

Page 11: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

(Chances are I’m repeating it right now.)

Page 12: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Alan Kay

Page 13: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

3things

OOP

Page 14: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

EncapsulationLocal

RetentionProtection

Hidingof State-process

Page 15: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Genericity

Commonly, PolymophisimAlan Kay spoke of Algebras

Extreme late binding

Page 16: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Messaging

Object decides how to react.

Page 17: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

OOP

EncapsulationGenericityMessaging

Page 18: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Classes

Page 19: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Inheritance

Page 20: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

“Five words

objectmessageclassinstancemethod

make up the vocabulary with which Smalltalk

is discussed.”

Smalltalk-80, The Language, p.51

Page 21: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Smalltalk 71727680

Classes

Inheritance

Metaclasses

Page 22: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Alan Kay2003

“So I decided to leave out inheritance as a built-in feature until I understood it better.”

Page 23: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Alan Kay2003

“[...] backslid towards Simula and did not replace the extension mechanisms with safer ones that were anywhere near as useful.”

Page 24: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Classical

Page 25: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Sketchpad

1963

Page 26: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Generalvs.

Specific

Page 27: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Simula-67

C++Javaetc.

Page 28: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Classes Instances

Page 29: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Segregation

Page 30: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Plato

Formvs.

Matter

Page 31: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Descriptionvs.

Representation

Page 32: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Classes Instances

Page 33: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object
Page 34: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Metaclass

“Class of classes”

Page 35: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object
Page 36: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object
Page 37: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

RubyRuby Logo © 2006, Yukihiro Matsumoto

Page 38: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

I’m not smart enough for Ruby’s

object system.

Page 39: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Peter DeutschThe Past, Present, and Future of Smalltalk

1989

“metaclasses have proven confusing to many users, and perhaps in the balance more confusing than valuable.”

Page 40: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Accidental Complexity

Page 41: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

William of Ockham

“entia non sunt multiplicanda praeter necessitatem”

Page 42: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

William of Ockham

“entities must not be multiplied beyond necessity”

Page 43: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Prototypal

Page 44: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Henry LiebermanOOPSLA 1986

http://web.media.mit.edu/~lieber/Lieberary/OOP/Delegation/Delegation.html

Using Prototypical Objects to Implement Shared Behavior in Object Oriented Systems

Page 45: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Self

1987

Page 46: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object
Page 47: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object
Page 48: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object
Page 49: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object
Page 50: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Abstractions

Objects

(Classes)

Page 51: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Objects

Abstractions?

Page 52: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

one

one = object.clone

Page 53: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

one two

two = one.clone

Page 54: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

P

one two three .....

one = proto.clonetwo = proto.clone

three = proto.clone

Page 55: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

YouAin’tGonnaNeed It

Page 56: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Singleton

Page 57: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Singleton (in JS)

var singleton = { ...};

Page 58: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Ex-Nihilo

“Out of Nothing”

Page 59: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Singleton: Self

clone = (self)

Page 60: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Prototypal Singleton

singleton.clone = function() { return this;};

Page 61: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Hard-core Singleton

function Singleton() { return Singleton.prototype;}

Page 62: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Near Miss

Page 63: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Near Miss

Page 64: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Near MissDay

Kin

Page 65: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Near Miss

var kin = day.clone("Kin");

Page 66: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Near Miss

clone: function(name) { var o = Object.create(this); o.name = name; ... return o;},

Page 67: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Near Miss

... // independent existence. o.scale = 0; o.position = 0; o.time = 0; ...

Page 68: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Object.create()

• ES5

• Firefox 4

• Safari 5

• Chrome 5+

• http://kangax.github.com/es5-compat-table/

Page 69: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Object.create()

Object.create = function(o) { function F() {}; F.prototype = (o || {}); return new F();}

http://javascript.crockford.com/prototypal.html

Page 70: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Nested Context

Page 71: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Nested Context

Like {block scope}.

(Or function scope in Javascript.)

Page 72: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Nested Context

under: function(path, f) { var m = Object.create(this); m.cd(path); f(m);},

Page 73: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Performance

Page 74: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Structured Memory

Page 75: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Programming as Experience:The Inspiration for Self

1995

Self runs

“2.3 times slower than optimized C++.”

Page 76: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Self includes: SmalltalkMario Wolczko

“all [sample] Smalltalk programs run faster in the the Self system, some significantly more so.”

Page 77: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Omega

1990Statically-typed prototypes

Page 78: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Design-Timevs.

Run-Time

Page 79: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Kevo

1993Concatative

‘Clone families’

Page 80: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Lisaac

2003Compiled.

44% slower to 17% fasterthan c.

http://www.lisaac.org/documentation/benchmarks

Page 81: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

V8 Logo © 2006 Google

V82008

Page 82: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

V8 Logo © 2006 Google

Generated Code

Page 83: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

V8 Logo © 2006 Google

Hidden Classes

Page 84: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Javascript

1996

Page 85: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Javascript

Is not an Object-Oriented Programming Language

Page 86: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Genericity

PASS

Page 87: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Messaging

FAIL*Partial support in ES5 and Harmony

Page 88: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Encapsulation

FAIL*Work-around with closure.

Page 89: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Peter DeutschThe Past, Present, and Future of Smalltalk

1989

“inheriting implementation [...] tends to create difficulties in subsequent evolution and often reflects insufficient understanding.”

Page 90: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Copyvs.

Delegation

Page 91: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Shared Data

Page 92: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Shared Data

Page 93: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Shared Data

Page 94: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Shared Data

......

...

...

......

Page 95: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Seph

Stateless Delgation

http://olabini.com/blog/2010/07/preannouncing-seph/

Page 96: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Sparse Objects

Page 97: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Sparse Objects

Page 98: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Sparse Objects

new Disk('Minute', unit.MS_S, 1, T("seconds/minute"), { colors: '#d22'})

Page 99: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Sparse Objectsnew Disk('Solar Year', unit.MS_D, T("days/~month"), 12, { colors: ['blue', 'green', 'orange', 'brown'], ...

Page 100: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Sparse Objects

... majorNames: ['~January'...], subDivide: 4, major: 3*4, median: 1*4, ...

Page 101: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Sparse Objects

... render: function(context) { context.save(); context.rotate( 6.28 * -9 / 365); ...

Page 102: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Flyweight

Page 103: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Flyweight

Page 104: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Flyweight

Page 105: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Flyweight

Page 106: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Flyweight

item: function(d) { var i = Object.create(this); i.dot = d; return i;},

Page 107: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Shared Behavior

Page 108: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Shared Behavior

Page 109: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Shared Behavior

Page 110: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Shared Behaviormint: function( head, pattern, action) { var my = this.dup(); my.head = head; my.pattern = pattern; my.action = action; return my;},

Page 111: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Shared Behavior

dup: function() { return Object.create(this);},

Page 112: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

*

*

*

Page 113: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Prototype

Instances

Page 114: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Do I use class patterns?

Page 115: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

YES

Page 116: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Do I use class patterns

for everything?

Page 117: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

NO

Page 118: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

a

Objects

Classes

Page 119: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

a

Self

Smalltalk

Page 120: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Classesare aUsefulPattern

Page 121: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

But notthe onlyPattern

Page 122: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Use Classes

Because You Want To

Page 123: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Use Classes

Because You Have To

Not

Page 124: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Review

Page 125: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

History

Page 126: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

OOP

Page 127: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Classical

Page 128: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Prototypal

Page 129: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Performance

Page 130: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

We’re Stuck with

Javascript

Page 131: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Learn How to Use It

Page 132: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Prototype

Instances

Page 133: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Shared Behavior

Page 134: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Shared Data

Page 135: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Singleton

Page 136: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Flyweight

Page 137: Classes Are Premature Optimization · object system. Peter Deutsch The Past, Present, and Future of Smalltalk 1989 ... Using Prototypical Objects to Implement Shared Behavior in Object

Nested Context