SlideShare a Scribd company logo
1 of 44
Download to read offline
Object-oriented
                         !quot;#$




programming in
   Smalltalk
     Alexandre Bergel
    RMoD team, INRIA,
        Lille, France
   alexandre@bergel.eu
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
Outline



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



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




                              color = data
                              shape = behavior


(Flatt 98)
Procedural programming




(Flatt 98)
Expressing combination
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;#$
Expressing extension
Expressing extension
Situation with some difficulties
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
Object as programming entities




                       a student

printDescription()      name=Bill
                     courses={c1, c2}
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
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
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
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
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
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
Outline



1. Essence of class-based object orientation
2. Object oriented programming with Smalltalk
3. Smalltalk in Action
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


        SqueakByExample.org
   Free download — Print-on-demand
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 + 4



Keyword messages
                  3 raisedTo: 10 modulo: 5

                  Transcript show: 'hello world'
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
Statements and cascades

   Temporary variables
                          Statement

        | p pen |
        p := 100@100.
        pen := Pen new.
        pen up.
        pen goto: p; down; goto: p+p

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




 max: aNumber
 
 ^ self < aNumber
 
 
 ifTrue: [aNumber]
 
 
 ifFalse: [self]
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
Creating classes
Send a message to a class (!)


        Number subclass: #Complex
        
 instanceVariableNames: 'real imaginary'
        
 classVariableNames: ''
        
 poolDictionaries: ''
        
 category: 'ComplexNumbers'
Outline



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

More Related Content

What's hot

Evaluation of Exception Handling Metrics
Evaluation of Exception Handling MetricsEvaluation of Exception Handling Metrics
Evaluation of Exception Handling MetricsIJASCSE
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsITNet
 
M Gumbel - SCABIO: a framework for bioinformatics algorithms in Scala
M Gumbel - SCABIO: a framework for bioinformatics algorithms in ScalaM Gumbel - SCABIO: a framework for bioinformatics algorithms in Scala
M Gumbel - SCABIO: a framework for bioinformatics algorithms in ScalaJan Aerts
 
Inheritance (1)
Inheritance (1)Inheritance (1)
Inheritance (1)sanya6900
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsRai University
 
Introduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutletIntroduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutletOldingz
 

What's hot (9)

Evaluation of Exception Handling Metrics
Evaluation of Exception Handling MetricsEvaluation of Exception Handling Metrics
Evaluation of Exception Handling Metrics
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
 
Inheritance
InheritanceInheritance
Inheritance
 
M Gumbel - SCABIO: a framework for bioinformatics algorithms in Scala
M Gumbel - SCABIO: a framework for bioinformatics algorithms in ScalaM Gumbel - SCABIO: a framework for bioinformatics algorithms in Scala
M Gumbel - SCABIO: a framework for bioinformatics algorithms in Scala
 
JavaYDL11
JavaYDL11JavaYDL11
JavaYDL11
 
Inheritance (1)
Inheritance (1)Inheritance (1)
Inheritance (1)
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
 
JAVA CONCEPTS
JAVA CONCEPTS JAVA CONCEPTS
JAVA CONCEPTS
 
Introduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutletIntroduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutlet
 

Viewers also liked

Pharo: Objects at your Fingertips
Pharo: Objects at your FingertipsPharo: Objects at your Fingertips
Pharo: Objects at your FingertipsMarcus Denker
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakMarcus Denker
 
The Pharo Programming Language
The Pharo Programming LanguageThe Pharo Programming Language
The Pharo Programming Languagebergel
 
Squeak & Pharo @ NYC Smalltalk
Squeak & Pharo @ NYC SmalltalkSqueak & Pharo @ NYC Smalltalk
Squeak & Pharo @ NYC SmalltalkSeanDeNigris
 
Pharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntaxPharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntaxPharo
 
Pharo tutorial at ECOOP 2013
Pharo tutorial at ECOOP 2013Pharo tutorial at ECOOP 2013
Pharo tutorial at ECOOP 2013Pharo
 
Pharo Roadmap
Pharo RoadmapPharo Roadmap
Pharo RoadmapESUG
 
You Can’t Do That With Smalltalk!
You Can’t Do That With Smalltalk!You Can’t Do That With Smalltalk!
You Can’t Do That With Smalltalk!ESUG
 
Pharo Hands-on: 05 object model
Pharo Hands-on: 05 object modelPharo Hands-on: 05 object model
Pharo Hands-on: 05 object modelPharo
 
Haskell vs. F# vs. Scala
Haskell vs. F# vs. ScalaHaskell vs. F# vs. Scala
Haskell vs. F# vs. Scalapt114
 

Viewers also liked (12)

Pharo: Objects at your Fingertips
Pharo: Objects at your FingertipsPharo: Objects at your Fingertips
Pharo: Objects at your Fingertips
 
Pharo devnology20150401
Pharo devnology20150401Pharo devnology20150401
Pharo devnology20150401
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
 
The Pharo Programming Language
The Pharo Programming LanguageThe Pharo Programming Language
The Pharo Programming Language
 
Squeak & Pharo @ NYC Smalltalk
Squeak & Pharo @ NYC SmalltalkSqueak & Pharo @ NYC Smalltalk
Squeak & Pharo @ NYC Smalltalk
 
Pharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntaxPharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntax
 
Pharo tutorial at ECOOP 2013
Pharo tutorial at ECOOP 2013Pharo tutorial at ECOOP 2013
Pharo tutorial at ECOOP 2013
 
Pharo Roadmap
Pharo RoadmapPharo Roadmap
Pharo Roadmap
 
You Can’t Do That With Smalltalk!
You Can’t Do That With Smalltalk!You Can’t Do That With Smalltalk!
You Can’t Do That With Smalltalk!
 
Pharo Hands-on: 05 object model
Pharo Hands-on: 05 object modelPharo Hands-on: 05 object model
Pharo Hands-on: 05 object model
 
Haskell vs. F# vs. Scala
Haskell vs. F# vs. ScalaHaskell vs. F# vs. Scala
Haskell vs. F# vs. Scala
 
Stoop 432-singleton
Stoop 432-singletonStoop 432-singleton
Stoop 432-singleton
 

More from bergel

Building Neural Network Through Neuroevolution
Building Neural Network Through NeuroevolutionBuilding Neural Network Through Neuroevolution
Building Neural Network Through Neuroevolutionbergel
 
Roassal presentation
Roassal presentationRoassal presentation
Roassal presentationbergel
 
2011 famoosr
2011 famoosr2011 famoosr
2011 famoosrbergel
 
2011 ecoop
2011 ecoop2011 ecoop
2011 ecoopbergel
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleannessbergel
 
Multi dimensional profiling
Multi dimensional profilingMulti dimensional profiling
Multi dimensional profilingbergel
 
Profiling blueprints
Profiling blueprintsProfiling blueprints
Profiling blueprintsbergel
 
2008 Sccc Inheritance
2008 Sccc Inheritance2008 Sccc Inheritance
2008 Sccc Inheritancebergel
 
Presentation of Traits
Presentation of TraitsPresentation of Traits
Presentation of Traitsbergel
 
2006 Seaside
2006 Seaside2006 Seaside
2006 Seasidebergel
 
2006 Small Scheme
2006 Small Scheme2006 Small Scheme
2006 Small Schemebergel
 
2004 Esug Prototalk
2004 Esug Prototalk2004 Esug Prototalk
2004 Esug Prototalkbergel
 
2005 Oopsla Classboxj
2005 Oopsla Classboxj2005 Oopsla Classboxj
2005 Oopsla Classboxjbergel
 
2006 Esug Omnibrowser
2006 Esug Omnibrowser2006 Esug Omnibrowser
2006 Esug Omnibrowserbergel
 

More from bergel (14)

Building Neural Network Through Neuroevolution
Building Neural Network Through NeuroevolutionBuilding Neural Network Through Neuroevolution
Building Neural Network Through Neuroevolution
 
Roassal presentation
Roassal presentationRoassal presentation
Roassal presentation
 
2011 famoosr
2011 famoosr2011 famoosr
2011 famoosr
 
2011 ecoop
2011 ecoop2011 ecoop
2011 ecoop
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleanness
 
Multi dimensional profiling
Multi dimensional profilingMulti dimensional profiling
Multi dimensional profiling
 
Profiling blueprints
Profiling blueprintsProfiling blueprints
Profiling blueprints
 
2008 Sccc Inheritance
2008 Sccc Inheritance2008 Sccc Inheritance
2008 Sccc Inheritance
 
Presentation of Traits
Presentation of TraitsPresentation of Traits
Presentation of Traits
 
2006 Seaside
2006 Seaside2006 Seaside
2006 Seaside
 
2006 Small Scheme
2006 Small Scheme2006 Small Scheme
2006 Small Scheme
 
2004 Esug Prototalk
2004 Esug Prototalk2004 Esug Prototalk
2004 Esug Prototalk
 
2005 Oopsla Classboxj
2005 Oopsla Classboxj2005 Oopsla Classboxj
2005 Oopsla Classboxj
 
2006 Esug Omnibrowser
2006 Esug Omnibrowser2006 Esug Omnibrowser
2006 Esug Omnibrowser
 

Recently uploaded

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 

Recently uploaded (20)

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 

Object-oriented programming in Smalltalk

  • 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
  • 5. Procedural programming color = data shape = behavior (Flatt 98)
  • 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;#$
  • 11. Situation with some difficulties
  • 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
  • 22. The origin of Smalltalk Alan Kay’s Dynabook project (1968) Alto — Xerox PARC (1973)
  • 28. Squeak resources www.squeak.org www.seaside.st Downloads and links One-click image SqueakByExample.org Free download — Print-on-demand
  • 31. Everything happens by sending messages
  • 33. Do it, print it You can evaluate any expression anywhere in Smalltalk
  • 36. Syntax in a Nutshell
  • 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. 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