SlideShare a Scribd company logo
S.Ducasse
Stéphane Ducasse
Stephane.Ducasse@univ-savoie.fr
http://www.listic.univ-savoie.fr/~ducasse/
1
Essential OO
Concepts
Stéphane Ducasse
stéphane.ducasse@univ-savoie.fr
S.Ducasse
License: CC-Attribution-ShareAlike 2.0
http://creativecommons.org/licenses/by-sa/2.0/
2
S.Ducasse 3
Outline
• OOP
• Objects, classes
• Inheritance
• Composition
• Comparison
S.Ducasse 4
Object-Orientation
• Is a paradigm not a technology
• Reflects, simulates the real world
• Thinks in terms of organization
• Tries to
• Handle complexity
• Enhance reusability
• Minimize maintenance cost
S.Ducasse 5
Evolution
• Procedures
• Structured Programming
• Fourth Generation Languages
• Object-Oriented Programming
• ???
S.Ducasse 6
Traditional Point of View
• Focuses upon procedures
• Functionality is vested in procedures
• Data exists solely to be operated upon by
procedures
• Procedures know about the structure of data
• Requires large number of procedures and
procedure names
S.Ducasse 7
Data and Procedures
S.Ducasse 8
Roadmap
• OOP
• Objects, classes
• Inheritance
• Composition
• Comparison
S.Ducasse 9
What is OOP?
• An application is a collection of interacting entities
(objects)
• Objects are characterized by behavior and state
• Inter-object behavior needs to be coordinated
• Inter-object communication is the key to
coordination
S.Ducasse 10
Object-Oriented Viewpoint
• An application is a set of objects interacting by
sending messages
• The functionality of an object is described by its
methods, its data are stored in private variables
• An object’s functionality can be invoked by sending
a message
• Everything is an object
S.Ducasse 11
State + Behavior + Identity
S.Ducasse 12
State + Behavior + Identity
• State: Objects it contains or refers to
• Ex: point location
• Behavior: an object understands a given set of
messages
• Identity: an object can be the same (of the same
class) than another one but it has still a different
identity (location in memory)
S.Ducasse 13
Equality and Identity
• I want to eat the pizza that you are eating
• Equality: I want to eat the “same” kind of pizza
• Identity: I eat your pizza
S.Ducasse 14
Data/Messages/Methods
Data
Messages
Methods
S.Ducasse 15
What vs. How
• What: Messages
– Specify what behavior objects are to perform
– Details of how are left up to the receiver
– State information only accessed via messages
• How: Methods
– Specify how operation is to be performed
– Must have access to (contain or be passed) data
– Need detailed knowledge of data
– Can manipulate data directly
Data
Methods
Messages
S.Ducasse 16
Message
• Sent to receiver object: receiver-object message
• A message may include parameters necessary for
performing the action
• In Smalltalk, a message-send always returns a result
(an object)
• Only way to communicate with an object and have it
perform actions
pt h w
aRectangle
aClient
…
aRectangle area
…
area
S.Ducasse 17
Method
• Defines how to respond to a message
• Selected via method lookup technique
• Has name that is the same as message name
• Is a sequence of executable statements
• Returns an object as result of execution
pt h w
area
aRectangle
area
^ h * w
aClient
…
aRectangle area
…
area
S.Ducasse 18
Object Encapsulation
• Technique for
• Creating objects with encapsulated state/behaviour
• Hiding implementation details
• Protecting the state information of objects
• Communicating/accessing via a uniform interface
• Puts objects in control
• Facilitates modularity, code reuse and
maintenance
• External perspective vs. Internal
perspective
• What vs. How
• Message vs. Method
S.Ducasse 19
Encapsulation at Work
pt h w
area
area
aRectangle
area
^ h * w
aClient
…
aRectangle area
…
area
area
aRectangle
area
d := (pt2-pt1).
^ d x * d y
aClient
…
aRectangle area
…
pt1 pt2
S.Ducasse 20
Objects
Unique identity
Private state
Shared behavior among other similar objects
S.Ducasse 21
Roadmap
• OOP
• Objects, classes
• Classes and Inheritance
• Composition
• Comparison
S.Ducasse 22
Class: Factory of Objects
• Reuse behavior
• => Factor into class
• Class: “Factory” object for creating new objects of
the same kind
• Template for objects that share common
characteristics
generates
S.Ducasse 23
Class: Mold of Objects
• Describe state but not value of all the instances of
the class
– Position, width and height for rectangles
• Define behavior of all instances of the class
• area
• ^ width * height
S.Ducasse 24
Instances
• A particular occurrence of an object defined by a
class
• Each instance has its own value for the instance
variables
• All instances of a class share
the same methods
400@10
100
20
300@20
10
140
S.Ducasse 25
How to Share Specification?
• Do not want to rewrite everything!
• Often times want small changes
• Class hierarchies for sharing of definitions
• Each class defines or refines the definition of its
ancestors
• => inheritance
S.Ducasse 26
Inheritance
• New classes
• Can add state and behavior
• Can specialize ancestor behavior
• Can use ancestor’s behavior and state
• Can hide ancestor’s behavior
• Direct ancestor = superclass
• Direct descendant = subclass
S.Ducasse 27
Comparable Quantity
Hierarchy
S.Ducasse 28
Polymorphism - Late binding
• Same message can be sent to different objects
• Different receivers react differently (different
methods)
• aCircle area
• aRectangle area
• aColoredWindow open
• aScheduledWindow open
• aWindow open
S.Ducasse 29
Late binding: “Let’s the receiver
decide”
Mapping of messages to methods deferred until run-
time (dynamic binding)
Allows for rapid incremental development without
the need to recompile the complete applications
Most traditional languages do this at compile time
(static binding)
S.Ducasse 30
Roadmap
• OOP
• Objects, classes
• Classes and Inheritance
• Composition
• Comparison
S.Ducasse 31
Composition
• An object is composed of other objects
• in a part-of relationship
• The object uses its parts to implement its
behavior
• The object can delegate to its parts
S.Ducasse 32
Example
A rectangle can be composed of
two points:
to represent its origin and extent
to represent its topleft and bottomleft corners
or 4 numbers
S.Ducasse 33
Example (2)
Polyline has a list of vertices
S.Ducasse 34
Composition vs. Inheritance
Inheritance supports extension: ColoredRectangle
But
static, properties are difficult to change dynamically
we have to change classes at run-time
explosion of classes
class with too much responsibilities
With composition
run-time changes are easier: plug another objects
(with the same interface)
but lot of objects
S.Ducasse 35
Outline
• OOP
• Objects, classes
• Inheritance
• Composition
• Comparison
S.Ducasse 36
Graphical Editor
• Managing list of objects: square, rectangle,
circle...
• Intersect, color, rotate translate….
• We want to know the total area of a list of figures
S.Ducasse 37
Procedural Solution
tArea
element class = Circle
then tArea := tArea + element.circleArea.
element class= Rectangle
then tArea := tArea + element.rectangleArea
…
Same for ...
intersect, color, rotate translate….
S.Ducasse 38
In Java for example
public static long sumShapes(Shape shapes[]) {
long sum = 0;
for (int i=0; i<shapes.length; i++) {
switch (shapes[i].kind()) {
// a class constant
case Shape.CIRCLE:
sum += shapes[i].circleArea();
break;
case Shape.RECTANGLE:
sum += shapes[i].rectangleArea();
break;
... // more cases
}
}
return sum;
}
S.Ducasse 39
Problems
• Adding a kind of graphical element
• Change all the methods area, intersect, rotate,
translate…
• Always have to check what is the data I
manipulate
S.Ducasse 40
Object-Oriented Solution
•Circle>>area
• ^ Float pi * r * r
•Rectangle>>area
• ^ width * height
•XXX>>area
• elements do:
• [:each | tArea := tArea + each area]
S.Ducasse 41
Advantages
• Adding a new graphical object does not require to
change the list operations
• I do not have know the kind of objects I’m
manipulating as soon as they all share a common
interface
S.Ducasse 42
Recap
OOP see the world as interacting objects
Objects
Have their own state
Share the behavior among similar objects
Classes: Factory of objects
Define behavior of objects
Describe the structure of objects
Share specification via hierarchies
S.Ducasse 43
Recap
• OOP is based on
– Encapsulating data and procedures
– Inheritance
– Polymorphism
– Late Binding
• OOP promotes
– Modularity
– Reuse

More Related Content

Viewers also liked

12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
The World of Smalltalk
 
Stoop 433-chain
Stoop 433-chainStoop 433-chain
Stoop 433-chain
The World of Smalltalk
 
Stoop 303-advanced blocks
Stoop 303-advanced blocksStoop 303-advanced blocks
Stoop 303-advanced blocks
The World of Smalltalk
 
11 - OOP - Numbers
11 - OOP - Numbers11 - OOP - Numbers
11 - OOP - Numbers
The World of Smalltalk
 
Stoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesignStoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesign
The World of Smalltalk
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
The World of Smalltalk
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
The World of Smalltalk
 
10 reflection
10 reflection10 reflection
10 reflection
The World of Smalltalk
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
The World of Smalltalk
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
The World of Smalltalk
 
Stoop 416-lsp
Stoop 416-lspStoop 416-lsp
Stoop 416-lsp
The World of Smalltalk
 
Stoop 431-visitor
Stoop 431-visitorStoop 431-visitor
Stoop 431-visitor
The World of Smalltalk
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
The World of Smalltalk
 
Stoop 400 o-metaclassonly
Stoop 400 o-metaclassonlyStoop 400 o-metaclassonly
Stoop 400 o-metaclassonly
The World of Smalltalk
 
Stoop 430-design patternsintro
Stoop 430-design patternsintroStoop 430-design patternsintro
Stoop 430-design patternsintro
The World of Smalltalk
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
The World of Smalltalk
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
The World of Smalltalk
 
Double Dispatch
Double DispatchDouble Dispatch
Double Dispatch
The World of Smalltalk
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
The World of Smalltalk
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
The World of Smalltalk
 

Viewers also liked (20)

12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
Stoop 433-chain
Stoop 433-chainStoop 433-chain
Stoop 433-chain
 
Stoop 303-advanced blocks
Stoop 303-advanced blocksStoop 303-advanced blocks
Stoop 303-advanced blocks
 
11 - OOP - Numbers
11 - OOP - Numbers11 - OOP - Numbers
11 - OOP - Numbers
 
Stoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesignStoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesign
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
 
10 reflection
10 reflection10 reflection
10 reflection
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
 
Stoop 416-lsp
Stoop 416-lspStoop 416-lsp
Stoop 416-lsp
 
Stoop 431-visitor
Stoop 431-visitorStoop 431-visitor
Stoop 431-visitor
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop 400 o-metaclassonly
Stoop 400 o-metaclassonlyStoop 400 o-metaclassonly
Stoop 400 o-metaclassonly
 
Stoop 430-design patternsintro
Stoop 430-design patternsintroStoop 430-design patternsintro
Stoop 430-design patternsintro
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
Double Dispatch
Double DispatchDouble Dispatch
Double Dispatch
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 

Similar to 7 - OOP - OO Concepts

1 - OOP
1 - OOP1 - OOP
Stoop 421-design heuristics
Stoop 421-design heuristicsStoop 421-design heuristics
Stoop 421-design heuristics
The World of Smalltalk
 
2 - OOP
2 - OOP2 - OOP
4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)
The World of Smalltalk
 
Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
The World of Smalltalk
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
The World of Smalltalk
 
8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_feb
Raj Shah
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
DurgaPrasadVasantati
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
DurgaPrasadVasantati
 
Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0
Ganapathi M
 
Duraspace Hot Topics Series 6: Metadata and Repository Services
Duraspace Hot Topics Series 6: Metadata and Repository ServicesDuraspace Hot Topics Series 6: Metadata and Repository Services
Duraspace Hot Topics Series 6: Metadata and Repository Services
Matthew Critchlow
 
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...
DuraSpace
 
Uniform and Safe Metaclass Composition
Uniform and Safe Metaclass CompositionUniform and Safe Metaclass Composition
Uniform and Safe Metaclass Composition
ESUG
 
Stoop 304-metaclasses
Stoop 304-metaclassesStoop 304-metaclasses
Stoop 304-metaclasses
The World of Smalltalk
 
34. uml
34. uml34. uml
34. uml
karzansaid
 
Stoop 434-composite
Stoop 434-compositeStoop 434-composite
Stoop 434-composite
The World of Smalltalk
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
Nicolò Calcavecchia
 
Artificial Intelligence: Knowledge Acquisition
Artificial Intelligence: Knowledge AcquisitionArtificial Intelligence: Knowledge Acquisition
Artificial Intelligence: Knowledge Acquisition
The Integral Worm
 
Class 5-introto dl
Class 5-introto dlClass 5-introto dl
Class 5-introto dl
madhuvardhan
 
Class 5-introto dl
Class 5-introto dlClass 5-introto dl
Class 5-introto dl
madhuvardhan
 

Similar to 7 - OOP - OO Concepts (20)

1 - OOP
1 - OOP1 - OOP
1 - OOP
 
Stoop 421-design heuristics
Stoop 421-design heuristicsStoop 421-design heuristics
Stoop 421-design heuristics
 
2 - OOP
2 - OOP2 - OOP
2 - OOP
 
4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)
 
Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_feb
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
 
Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0
 
Duraspace Hot Topics Series 6: Metadata and Repository Services
Duraspace Hot Topics Series 6: Metadata and Repository ServicesDuraspace Hot Topics Series 6: Metadata and Repository Services
Duraspace Hot Topics Series 6: Metadata and Repository Services
 
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...
 
Uniform and Safe Metaclass Composition
Uniform and Safe Metaclass CompositionUniform and Safe Metaclass Composition
Uniform and Safe Metaclass Composition
 
Stoop 304-metaclasses
Stoop 304-metaclassesStoop 304-metaclasses
Stoop 304-metaclasses
 
34. uml
34. uml34. uml
34. uml
 
Stoop 434-composite
Stoop 434-compositeStoop 434-composite
Stoop 434-composite
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
 
Artificial Intelligence: Knowledge Acquisition
Artificial Intelligence: Knowledge AcquisitionArtificial Intelligence: Knowledge Acquisition
Artificial Intelligence: Knowledge Acquisition
 
Class 5-introto dl
Class 5-introto dlClass 5-introto dl
Class 5-introto dl
 
Class 5-introto dl
Class 5-introto dlClass 5-introto dl
Class 5-introto dl
 

More from The World of Smalltalk

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
The World of Smalltalk
 
99 questions
99 questions99 questions
13 traits
13 traits13 traits
11 bytecode
11 bytecode11 bytecode
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
The World of Smalltalk
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
The World of Smalltalk
 
06 debugging
06 debugging06 debugging
05 seaside
05 seaside05 seaside
04 idioms
04 idioms04 idioms
02 basics
02 basics02 basics
01 intro
01 intro01 intro
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
The World of Smalltalk
 
Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
The World of Smalltalk
 

More from The World of Smalltalk (14)

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
 
99 questions
99 questions99 questions
99 questions
 
13 traits
13 traits13 traits
13 traits
 
11 bytecode
11 bytecode11 bytecode
11 bytecode
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
06 debugging
06 debugging06 debugging
06 debugging
 
05 seaside
05 seaside05 seaside
05 seaside
 
04 idioms
04 idioms04 idioms
04 idioms
 
02 basics
02 basics02 basics
02 basics
 
01 intro
01 intro01 intro
01 intro
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 
Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
 

Recently uploaded

How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 

7 - OOP - OO Concepts

  • 3. S.Ducasse 3 Outline • OOP • Objects, classes • Inheritance • Composition • Comparison
  • 4. S.Ducasse 4 Object-Orientation • Is a paradigm not a technology • Reflects, simulates the real world • Thinks in terms of organization • Tries to • Handle complexity • Enhance reusability • Minimize maintenance cost
  • 5. S.Ducasse 5 Evolution • Procedures • Structured Programming • Fourth Generation Languages • Object-Oriented Programming • ???
  • 6. S.Ducasse 6 Traditional Point of View • Focuses upon procedures • Functionality is vested in procedures • Data exists solely to be operated upon by procedures • Procedures know about the structure of data • Requires large number of procedures and procedure names
  • 7. S.Ducasse 7 Data and Procedures
  • 8. S.Ducasse 8 Roadmap • OOP • Objects, classes • Inheritance • Composition • Comparison
  • 9. S.Ducasse 9 What is OOP? • An application is a collection of interacting entities (objects) • Objects are characterized by behavior and state • Inter-object behavior needs to be coordinated • Inter-object communication is the key to coordination
  • 10. S.Ducasse 10 Object-Oriented Viewpoint • An application is a set of objects interacting by sending messages • The functionality of an object is described by its methods, its data are stored in private variables • An object’s functionality can be invoked by sending a message • Everything is an object
  • 11. S.Ducasse 11 State + Behavior + Identity
  • 12. S.Ducasse 12 State + Behavior + Identity • State: Objects it contains or refers to • Ex: point location • Behavior: an object understands a given set of messages • Identity: an object can be the same (of the same class) than another one but it has still a different identity (location in memory)
  • 13. S.Ducasse 13 Equality and Identity • I want to eat the pizza that you are eating • Equality: I want to eat the “same” kind of pizza • Identity: I eat your pizza
  • 15. S.Ducasse 15 What vs. How • What: Messages – Specify what behavior objects are to perform – Details of how are left up to the receiver – State information only accessed via messages • How: Methods – Specify how operation is to be performed – Must have access to (contain or be passed) data – Need detailed knowledge of data – Can manipulate data directly Data Methods Messages
  • 16. S.Ducasse 16 Message • Sent to receiver object: receiver-object message • A message may include parameters necessary for performing the action • In Smalltalk, a message-send always returns a result (an object) • Only way to communicate with an object and have it perform actions pt h w aRectangle aClient … aRectangle area … area
  • 17. S.Ducasse 17 Method • Defines how to respond to a message • Selected via method lookup technique • Has name that is the same as message name • Is a sequence of executable statements • Returns an object as result of execution pt h w area aRectangle area ^ h * w aClient … aRectangle area … area
  • 18. S.Ducasse 18 Object Encapsulation • Technique for • Creating objects with encapsulated state/behaviour • Hiding implementation details • Protecting the state information of objects • Communicating/accessing via a uniform interface • Puts objects in control • Facilitates modularity, code reuse and maintenance • External perspective vs. Internal perspective • What vs. How • Message vs. Method
  • 19. S.Ducasse 19 Encapsulation at Work pt h w area area aRectangle area ^ h * w aClient … aRectangle area … area area aRectangle area d := (pt2-pt1). ^ d x * d y aClient … aRectangle area … pt1 pt2
  • 20. S.Ducasse 20 Objects Unique identity Private state Shared behavior among other similar objects
  • 21. S.Ducasse 21 Roadmap • OOP • Objects, classes • Classes and Inheritance • Composition • Comparison
  • 22. S.Ducasse 22 Class: Factory of Objects • Reuse behavior • => Factor into class • Class: “Factory” object for creating new objects of the same kind • Template for objects that share common characteristics generates
  • 23. S.Ducasse 23 Class: Mold of Objects • Describe state but not value of all the instances of the class – Position, width and height for rectangles • Define behavior of all instances of the class • area • ^ width * height
  • 24. S.Ducasse 24 Instances • A particular occurrence of an object defined by a class • Each instance has its own value for the instance variables • All instances of a class share the same methods 400@10 100 20 300@20 10 140
  • 25. S.Ducasse 25 How to Share Specification? • Do not want to rewrite everything! • Often times want small changes • Class hierarchies for sharing of definitions • Each class defines or refines the definition of its ancestors • => inheritance
  • 26. S.Ducasse 26 Inheritance • New classes • Can add state and behavior • Can specialize ancestor behavior • Can use ancestor’s behavior and state • Can hide ancestor’s behavior • Direct ancestor = superclass • Direct descendant = subclass
  • 28. S.Ducasse 28 Polymorphism - Late binding • Same message can be sent to different objects • Different receivers react differently (different methods) • aCircle area • aRectangle area • aColoredWindow open • aScheduledWindow open • aWindow open
  • 29. S.Ducasse 29 Late binding: “Let’s the receiver decide” Mapping of messages to methods deferred until run- time (dynamic binding) Allows for rapid incremental development without the need to recompile the complete applications Most traditional languages do this at compile time (static binding)
  • 30. S.Ducasse 30 Roadmap • OOP • Objects, classes • Classes and Inheritance • Composition • Comparison
  • 31. S.Ducasse 31 Composition • An object is composed of other objects • in a part-of relationship • The object uses its parts to implement its behavior • The object can delegate to its parts
  • 32. S.Ducasse 32 Example A rectangle can be composed of two points: to represent its origin and extent to represent its topleft and bottomleft corners or 4 numbers
  • 33. S.Ducasse 33 Example (2) Polyline has a list of vertices
  • 34. S.Ducasse 34 Composition vs. Inheritance Inheritance supports extension: ColoredRectangle But static, properties are difficult to change dynamically we have to change classes at run-time explosion of classes class with too much responsibilities With composition run-time changes are easier: plug another objects (with the same interface) but lot of objects
  • 35. S.Ducasse 35 Outline • OOP • Objects, classes • Inheritance • Composition • Comparison
  • 36. S.Ducasse 36 Graphical Editor • Managing list of objects: square, rectangle, circle... • Intersect, color, rotate translate…. • We want to know the total area of a list of figures
  • 37. S.Ducasse 37 Procedural Solution tArea element class = Circle then tArea := tArea + element.circleArea. element class= Rectangle then tArea := tArea + element.rectangleArea … Same for ... intersect, color, rotate translate….
  • 38. S.Ducasse 38 In Java for example public static long sumShapes(Shape shapes[]) { long sum = 0; for (int i=0; i<shapes.length; i++) { switch (shapes[i].kind()) { // a class constant case Shape.CIRCLE: sum += shapes[i].circleArea(); break; case Shape.RECTANGLE: sum += shapes[i].rectangleArea(); break; ... // more cases } } return sum; }
  • 39. S.Ducasse 39 Problems • Adding a kind of graphical element • Change all the methods area, intersect, rotate, translate… • Always have to check what is the data I manipulate
  • 40. S.Ducasse 40 Object-Oriented Solution •Circle>>area • ^ Float pi * r * r •Rectangle>>area • ^ width * height •XXX>>area • elements do: • [:each | tArea := tArea + each area]
  • 41. S.Ducasse 41 Advantages • Adding a new graphical object does not require to change the list operations • I do not have know the kind of objects I’m manipulating as soon as they all share a common interface
  • 42. S.Ducasse 42 Recap OOP see the world as interacting objects Objects Have their own state Share the behavior among similar objects Classes: Factory of objects Define behavior of objects Describe the structure of objects Share specification via hierarchies
  • 43. S.Ducasse 43 Recap • OOP is based on – Encapsulating data and procedures – Inheritance – Polymorphism – Late Binding • OOP promotes – Modularity – Reuse