Professional Documents
Culture Documents
Sommersemester 2015
Radu Muschevici
Software Engineering Group, Department of Computer Science
2015-04-28
1 / 22
Exam Date
Note: The lecture on Tuesday, 7 July 2015 will be used for review and
questions (no new content).
2 / 22
Prototype-based
Programming
3 / 22
http://www.selflanguage.org/
4 / 22
Design Goals
Simplicity
Everything is an object
6 / 22
The The
SelfObject
Object-Model
Example:
Model of Self
:x
paint
:y
how to paint objects
parent*
width
width:
height
height:
assignment primitives
overwrite the corresponding
get methods
parent*
height
height:
^width
:x
width: x
collection
of slotscontains
Every object
Each
slot has of
a name
collection
slots and an
object
Every
Each
slot
a nameasand an
slot
canhas
be marked
parent
slot
object
A non-method object simply
returns
Everyitself
slot when
can be
marked as
invoked
asparent
a method
slot
A method objects contains a
piece
of code thatsobject
executed
A non-method
simply
on invocation
returns itself when invoked as
Slots of method objects can
methodas argument slots
beamarked
Classes are abstract (In the real world, there are only objects)
8 / 22
o1
o2
o3
a
b
a
b
c
a
b
d
a
b
C2
C3
a
b
c
a
b
d
o1 = new C1();
o2 = new C2();
o3 = new C3();
9 / 22
10 / 22
o1
o2
o3
a
b
c
b
c
d
d
a
11 / 22
BC
b
c
C1
C2
C3
a
b
c
b
c
d
d
a
12 / 22
o2
o1
a
b
c
b
c
d
o3
d
a
13 / 22
Prototypes
Object Creation
14 / 22
Delegation
Smalltalk
instances and classes
how to
print objects
An object (superclass)
has parent(s) nil(sometime
(inst vars)
(none)
the prototype)
(methods)
(class)
(x)
(y)
3
5
7
9
how to
print objects
...
(class)
Point
(name)
Multiple parents
multiple
(superclass)
inheritance (inst
(diamond
problem
class, x, y
vars)
More exible
(methods)
than inheritance
SELF objects
parent*
+
how to
add points
etc.)
how to
add points
parent*
x
x:
y
y:
3
!
5
!
parent*
x
x:
y
y:
7
!
9
!
15 / 22
clone
+ remove height
+ change getArea() code
clone
+ add depth
+ remove getArea()
+ add getVolume()
3dBox
square
width
getArea() {width*width}
width
height
depth
getVolume() {width*height*depth}
16 / 22
parent*
...
parent*
...
width
width
30
height
10
height
depth
12
parent*
17 / 22
parent*
...
parent*
...
width
width
30
height
10
height
depth
12
parent*
18 / 22
parent*
parent*
...
width
height
10
parent*
width
height
32
19 / 22
Delegation
Class-based
Prototype-based
21 / 22
Download link:
http://bibliography.selflanguage.org/
organizing-programs.html
22 / 22