Object-oriented
                         !quot;#$




programming in
   Smalltalk
     Alexandre Bergel
    RMoD team, INR...
Goal of this lecture



 •   Gain elementary notions of object orientation

 •   Learn what is a pure object oriented lang...
Outline



1. Essence of class-based object orientation
2. Object oriented programming with Smalltalk
3. Smalltalk in Acti...
Outline



1. Essence of class-based object orientation
2. Object oriented programming with Smalltalk
3. Smalltalk in Acti...
Procedural programming




                              color = data
                              shape = behavior


(Fl...
Procedural programming




(Flatt 98)
Expressing combination
Example in C

struct Point {               struct Circle {
   const void * class;         const void * class;
   int x, y;...
Expressing extension
Expressing extension
Situation with some difficulties
Object-oriented programming


•   Simula 67 addressed the combinational explosion of data
    and behavior

•   a class is...
Object as programming entities




                       a student

printDescription()      name=Bill
                   ...
Object as programming entities


                                                                     ^ 'My name is ',
   ...
Object as programming entities


                                                                     ^ 'My name is ',
   ...
Object as programming entities


                                                                ^ 'My name is ',
        ...
Object as programming entities


                                                                3
                       ...
Object as programming entities


                                                                3
                       ...
Object-oriented programming
Encapsulation     Abstraction & Information Hiding



Composition       Nested Objects


Distr...
Outline



1. Essence of class-based object orientation
2. Object oriented programming with Smalltalk
3. Smalltalk in Acti...
Smalltalk
The origin of Smalltalk

          Alan Kay’s Dynabook project (1968)




                   Alto — Xerox PARC (1973)
Smalltalk today
Smalltalk today
Smalltalk today
Smalltalk today
Smalltalk today
Squeak resources


 www.squeak.org               www.seaside.st

Downloads and links           One-click image


        S...
Getting started
Everything is an object
Everything happens by sending
          messages
Running Squeak
Do it, print it




You can evaluate any
expression anywhere
    in Smalltalk
Standard development tools
Debuggers, Inspectors, Explorers
Syntax in a Nutshell
Three kind of messages

                      5 factorial
Unary messages        Transcript cr


Binary messages          3...
A typical method in the class Point
Method name      Argument               Comment


   <= aPoint
   
 quot;Answer whethe...
Statements and cascades

   Temporary variables
                          Statement

        | p pen |
        p := 100@10...
Control structures
Every control structure is realized by message sends
            4 timesRepeat: [Beeper beep]




 max:...
Control structures
Every control structure is realized by message sends
            4 timesRepeat: [Beeper beep]

        ...
Creating classes
Send a message to a class (!)


        Number subclass: #Complex
        
 instanceVariableNames: 'real ...
Outline



1. Essence of class-based object orientation
2. Object oriented programming with Smalltalk
3. Smalltalk in Acti...
2008 Sccc Smalltalk
Upcoming SlideShare
Loading in...5
×

2008 Sccc Smalltalk

1,202

Published on

After a short introduction to object orientation, this lecture gives an overview of the Smalltalk programming language.
This lecture was given on November 10, 2008, during the summer school on programming languages (http://pleiad.dcc.uchile.cl/pl2008/)

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,202
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

2008 Sccc Smalltalk

  1. 1. Object-oriented !quot;#$ programming in Smalltalk Alexandre Bergel RMoD team, INRIA, Lille, France alexandre@bergel.eu
  2. 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. 3. Outline 1. Essence of class-based object orientation 2. Object oriented programming with Smalltalk 3. Smalltalk in Action
  4. 4. Outline 1. Essence of class-based object orientation 2. Object oriented programming with Smalltalk 3. Smalltalk in Action
  5. 5. Procedural programming color = data shape = behavior (Flatt 98)
  6. 6. Procedural programming (Flatt 98)
  7. 7. Expressing combination
  8. 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;#$
  9. 9. Expressing extension
  10. 10. Expressing extension
  11. 11. Situation with some difficulties
  12. 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. 13. Object as programming entities a student printDescription() name=Bill courses={c1, c2}
  14. 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. 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. 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. 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. 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. 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. 20. Outline 1. Essence of class-based object orientation 2. Object oriented programming with Smalltalk 3. Smalltalk in Action
  21. 21. Smalltalk
  22. 22. The origin of Smalltalk Alan Kay’s Dynabook project (1968) Alto — Xerox PARC (1973)
  23. 23. Smalltalk today
  24. 24. Smalltalk today
  25. 25. Smalltalk today
  26. 26. Smalltalk today
  27. 27. Smalltalk today
  28. 28. Squeak resources www.squeak.org www.seaside.st Downloads and links One-click image SqueakByExample.org Free download — Print-on-demand
  29. 29. Getting started
  30. 30. Everything is an object
  31. 31. Everything happens by sending messages
  32. 32. Running Squeak
  33. 33. Do it, print it You can evaluate any expression anywhere in Smalltalk
  34. 34. Standard development tools
  35. 35. Debuggers, Inspectors, Explorers
  36. 36. Syntax in a Nutshell
  37. 37. Three kind of messages 5 factorial Unary messages Transcript cr Binary messages 3 + 4 Keyword messages 3 raisedTo: 10 modulo: 5 Transcript show: 'hello world'
  38. 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. 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. 40. Control structures Every control structure is realized by message sends 4 timesRepeat: [Beeper beep] max: aNumber ^ self < aNumber ifTrue: [aNumber] ifFalse: [self]
  41. 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. 42. Creating classes Send a message to a class (!) Number subclass: #Complex instanceVariableNames: 'real imaginary' classVariableNames: '' poolDictionaries: '' category: 'ComplexNumbers'
  43. 43. Outline 1. Essence of class-based object orientation 2. Object oriented programming with Smalltalk 3. Smalltalk in Action
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×