This document provides an overview of object-oriented programming concepts and the Smalltalk programming language. It discusses the essence of class-based object orientation, including classes, objects, encapsulation, inheritance and polymorphism. It then introduces the Smalltalk language, covering its history and development, core concepts like everything is an object and message passing, and how to get started programming in Smalltalk. Standard development tools and syntax like methods, statements, control structures and creating classes are also summarized.
1. Object-oriented
!quot;#$
programming in
Smalltalk
Alexandre Bergel
RMoD team, INRIA,
Lille, France
alexandre@bergel.eu
2. Goal of this lecture
• Gain elementary notions of object orientation
• Learn what is a pure object oriented language
• Increase the programming language section on your CV
3. Outline
1. Essence of class-based object orientation
2. Object oriented programming with Smalltalk
3. Smalltalk in Action
4. Outline
1. Essence of class-based object orientation
2. Object oriented programming with Smalltalk
3. Smalltalk in Action
8. Example in C
struct Point { struct Circle {
const void * class; const void * class;
int x, y; int x, y, rad;
}; };
void draw (void * self) { void move (void * self) {
switch(self[0]) { switch(self[0]) {
case POINT_CLASS: ... case POINT_CLASS: ...
case CIRCLE_CLASS: ... case CIRCLE_CLASS: ...
} }
} }
!quot;#$
12. Object-oriented programming
• Simula 67 addressed the combinational explosion of data
and behavior
• a class is an object factory
• class = superclass + attributes + methods
• object reactive to messages
13. Object as programming entities
a student
printDescription() name=Bill
courses={c1, c2}
14. Object as programming entities
^ 'My name is ',
Person name
age
gender
description()
Transcript show:
printDescription()
self description
a student
Student
printDescription() name=Bill instance courses super description,
courses={c1, c2} description() ' and I follows ',
courses
15. Object as programming entities
^ 'My name is ',
Person name
age
gender
description()
Transcript show:
printDescription()
self description
a student 1
Student
printDescription() name=Bill instance courses super description,
courses={c1, c2} description() ' and I follows ',
courses
16. Object as programming entities
^ 'My name is ',
Person name
age
gender
description()
Transcript show:
printDescription()
self description
a student 1
Student
description() name=Bill instance courses super description,
courses={c1, c2} description() ' and I follows ',
courses
2
17. Object as programming entities
3
^ 'My name is ',
Person name
age
gender
description()
Transcript show:
printDescription()
self description
a student 1
Student
super name=Bill instance courses super description,
description()
courses={c1, c2} description() ' and I follows ',
courses
2
18. Object as programming entities
3
^ 'My name is ',
Person name
age
gender
description()
Transcript show:
printDescription()
self description
a student 1
Student
super name=Bill instance courses super description,
description()
courses={c1, c2} description() ' and I follows ',
courses
2
19. Object-oriented programming
Encapsulation Abstraction & Information Hiding
Composition Nested Objects
Distribution of Separation of concerns
(e.g., HTML, CSS)
Responsibility
Message Passing Delegating responsibility
Conceptual hierarchy,
Inheritance polymorphism and reuse
20. Outline
1. Essence of class-based object orientation
2. Object oriented programming with Smalltalk
3. Smalltalk in Action
38. A typical method in the class Point
Method name Argument Comment
<= aPoint
quot;Answer whether the receiver is neither
below nor to the right of aPoint.quot;
^ x <= aPoint x and: [y <= aPoint y]
Return Binary message Block
Instance variable Keyword message
(2@3) <= (5@6) true
39. Statements and cascades
Temporary variables
Statement
| p pen |
p := 100@100.
pen := Pen new.
pen up.
pen goto: p; down; goto: p+p
Cascade
40. Control structures
Every control structure is realized by message sends
4 timesRepeat: [Beeper beep]
max: aNumber
^ self < aNumber
ifTrue: [aNumber]
ifFalse: [self]
41. Control structures
Every control structure is realized by message sends
4 timesRepeat: [Beeper beep]
Boolean
ifTrue:ifFalse:
max: aNumber True False
^ self < aNumber ifTrue:ifFalse: ifTrue:ifFalse:
ifTrue: [aNumber]
ifFalse: [self]
ifTrue: t ifFalse: f ifTrue: t ifFalse: f
^ t value ^ f value
42. Creating classes
Send a message to a class (!)
Number subclass: #Complex
instanceVariableNames: 'real imaginary'
classVariableNames: ''
poolDictionaries: ''
category: 'ComplexNumbers'
43. Outline
1. Essence of class-based object orientation
2. Object oriented programming with Smalltalk
3. Smalltalk in Action