SlideShare ist ein Scribd-Unternehmen logo
1 von 37
OO Basics
4/9/2024 1
Introduction to Object Orientation Topics
• Overview
• Basic Principles of Object Orientation
• Basic Concepts of Object Orientation
• Strengths of Object Orientation
4/9/2024 2
Overview
• What are object-oriented (OO) methods?
– OO methods provide a set of techniques for
analyzing, decomposing, and modularizing software
system architectures
– In general, OO methods are characterized by
structuring the system architecture on the basis of its
objects (and classes of objects) rather than the
actions it performs
• What are the benefits of OO?
– OO enhances key software quality factors of a system
and its constituent components
OO Basics 3
OOA, OOD, and OOP
• Object-oriented methods may be applied to
different phases in the software lifecycle
– e.g., analysis, design, implementation, etc.
• Object-oriented analysis (OOA) is a process of
discovery
– models and understands the requirements
of the system
• Object-oriented design (OOD) is a process of
invention and adaptation
– creates the abstractions and mechanisms
necessary to meet the system's behavioral
requirements determined during analysis
OO Basics 4
Basic Definitions OOD, and OOP
• Object-Oriented Design (OOD)
– A method for decomposing software architectures based
on the objects every system or subsystem manipulates
– Rather than "the" function it is meant to ensure
• Object-Oriented Programming (OOP)
– construction of software systems using object oriented
concepts as inheritance, polymorphism, encapsulation,
dynamic binding.
• Distinguish between OOD and OOP
– OOD is relatively independent of the programming
language used.
– OOP is primarily concerned with programming language
and software implementation issues
OO Basics 5
Object-Oriented Approach
• Model objects that are part of the problem
• Have objects exhibit their normal behavior
• Add objects that do not have problem-space
analogs
• Have the objects work together to create a
solution
Design patterns help you identify less-obvious
abstractions and the objects that can capture them.
- GOF
OO Basics 6
Five Basic Characteristics of OO
"Pure" object-orientation by Alan Kay (Smalltalk):
• Everything is an object.
• A program is a bunch of objects telling each
other what to do by sending messages.
• Each object has its own memory made up of
other objects.
• Every object has a type.
• All objects of a particular type can receive the
same message.
OO Basics 7
4/9/2024 8
Basic Principles of Object Orientation
Object Orientation
Encapsulation
Abstraction
Hierarchy
Polymorphism
What Is Abstraction?
• The essential characteristics of an entity that
distinguishes it from all other kinds of entities.
• Defines a boundary relative to the perspective of the
viewer.
• Is not a concrete manifestation, denotes the ideal
essence of something.
4/9/2024 9
Salesperson: Not
saying Which
salesperson – just a
salesperson in general!!!
Customer
Product
Manages Complexity
What Is Encapsulation?
• Hides implementation from clients.
– Clients depend on interface.
4/9/2024 10
Improves Resiliency
Encapsulation
• "Encapsulation is a mechanism used to hide the
data, internal structure, and implementation details
of an object. All interaction with the object is through
a public interface of operations." (Craig Larman)
• A boundary exists around each object;
– the boundary encapsulates the object’s characteristics
(data elements) and behaviors (functionality).
• The reason for hiding features is to:
(1) keep users from touching parts of the object
they shouldn’t touch;
(2) allows creator of the object to change the object’s internal
working without affecting the users of the object.
4/9/2024 11
What Is Polymorphism?
• The ability to hide many different
implementations behind a single interface.
4/9/2024 12
Manufacturer A
Manufacturer B
Manufacturer C
OO Principle:
Encapsulation Remote Control
Polymorphism
• Occurs with inheritance.
• Different subclasses may have different
implementations of the identical operations
• Allows you to treat an object as the base class,
rather than as a specific inherited type.
• Programmer doesn’t have to keep track of the
specific subclasses, the system selects the correct
operation based on the object type.
• Accomplished at run time using dynamic binding.
– lets you substitute objects that have identical interfaces for
each other at run-time.
4/9/2024 13
What is Hierarchy?
4/9/2024 14
Decreasing
abstraction
Increasing
abstraction
Asset
RealEstate
Savings
BankAccount
Checking Stock
Security
Bond
Elements at the same level of the hierarchy
should be at the same level of abstraction
Levels of abstraction
Basic Concepts of Object Orientation
• Object
• Class
• Attribute
• Operation
• Interface
• Package
• Relationships
4/9/2024 15
What is an Object?
• Informally, an object represents an entity, either
physical, conceptual, or software
– Physical entity
– Conceptual entity
– Software entity
4/9/2024 16
Truck
Chemical Process
Linked List
A More Formal Definition
• An object is a concept, abstraction, or thing with
sharp boundaries and meaning for an
application
• An object is something that has:
– State
– Behavior
– Identity
4/9/2024 17
What is a Class?
• A class is a description of a group of objects with
common properties (attributes), behavior
(operations), relationships, and semantics
– An object is an instance of a class
• A class is an abstraction in that it:
– Emphasizes relevant characteristics
– Suppresses other characteristics
4/9/2024 18
OO Principle: Abstraction
4/9/2024 19
Sample Class
a + b = 10
Class
Course
Properties
Name
Location
Days offered
Credit hours
Start time
End time
Behavior
Add a student
Delete a student
Get course roster
Determine if it is full
Representing Classes in the UML
• A class is represented using a rectangle with
three compartments:
– The class name
– The structure (attributes)
– The behavior (operations)
4/9/2024 20
Professor
- name
- employeeID : UniqueId
- hireDate
- status
- discipline
- maxLoad
+ submitFinalGrade()
+ acceptCourseOffering()
+ setMaxLoad()
+ takeSabbatical()
+ teachClass()
Classes of Objects
• How many classes do you see?
4/9/2024 21
Classes and Objects Relationship
• A class is an abstract definition of an object
– It defines the structure and behavior of each object in
the class
– It serves as a template for creating objects
• Objects are grouped into classes
4/9/2024 22
Objects Class
Professor Smith
Professor Jones
Professor Mellon
Professor
What Is an Attribute?
• An attribute is a named property of a class that
describes the range of values that instances of
the property may hold.
– A class may have any number of attributes or no
attributes at all.
4/9/2024 23
Attributes
Student
- name
- address
- studentID
- dateOfBirth
What Is an Operation?
• A service that can be requested from an object
to effect behavior. An operation has a signature,
which may restrict the actual parameters that are
possible.
• A class may have any number of operations or
none at all.
4/9/2024 24
Operations
Student
+ get tuition()
+ add schedule()
+ get schedule()
+ delete schedule()
+ has prerequisites()
What is an Interface?
• Interfaces formalize polymorphism
• Interfaces support “plug-and-play” architectures
4/9/2024 25
Tube
Pyramid
Cube
Shape
Draw
Move
Scale
Rotate
<<interface>>
Realization relationship (stay tuned for realization relationships)
Interface
• How do you get an object to do useful work for
you?
• Objects are known only through their interfaces
• Every object presents an interface to the world.
• Interface determines what you can get an object
to do.
• Represent a "contract" with other objects.
• Communicate with objects by sending messages
to them; an object’s interface is the set of
messages an object will respond to.
4/9/2024 26
What is a Package?
• A package is a general purpose mechanism for
organizing elements into groups
• A model element which can contain other model
elements
• Uses
– Organize the model under development
– A unit of configuration managemen
4/9/2024 27
Package Name
Relationships
• Association
– Aggregation
• Dependency
• Inheritance
• Realization
4/9/2024 28
ConsoleWindow
Window
open()
close()
move()
display()
handleEvent()
Event
DialogBox Control
association
generalization
Relationships: Association
• Models a semantic connection among classes
4/9/2024 29
Professor University
Works for
Class
Association
Association Name
Relationships: Association Aggregation
• To model a “whole/part” relationship, use
aggregation.
• Aggregation represents a “has-a” or “is a part-of”
relationship, meaning that an object of the whole
has objects of the part.
[Martin Fowler]
30
4/9/2024
Company Department
*
1
Association: Multiplicity and Navigation
• Multiplicity defines how many objects participate
in a relationships
– Specified for each end of the association
• Associations are bi-directional by default, but it is
often desirable to restrict navigation to one
direction
4/9/2024 31
Customer Account
1 0..*
Multiplicity
Navigation
Relationships: Dependency
• A relationship between two model elements where a
change in one may cause a change in the other
– E.g. Class A depends on class B: method of A manipulates
objects of B in the parameters, local variables, or return types
4/9/2024 32
Package
ClientPackage SupplierPackage
Client Supplier
Class
Dependency
relationship
Relationships: Realization
4/9/2024 33
Tube
Pyramid
Cube
Shape
Draw
Move
Scale
Rotate
<<interface>>
Realization relationship (stay tuned for realization relationships)
4/9/2024 34
Inheritance
[Martin Fowler]
Shape
origin
draw()
erase()
move()
setColor()
getColor()
Circle
draw()
erase()
Square
draw()
erase()
move()
4/9/2024 35
Polymorphism
[Martin Fowler]
Goose
move()
Penguin
move()
FlockManager
reLocate()
Bird
move()
What Gets Inherited?
• A subclass inherits its parent’s attributes,
operations, and relationships
• A subclass may:
– Add additional attributes, operations, relationships
– Redefine inherited operations (use caution!)
• Common attributes, operations, and/or
relationships are shown at the highest applicable
level in the hierarchy
4/9/2024 36
Inheritance leverages the similarities among classes
4/9/2024 37
Example: What Gets Inherited
Truck
tonnage
GroundVehicle
weight
licenseNumber
Car
owner
register( )
getTax( )
Person
0..*
Trailer
1
Superclass
(parent)
Subclass
generalization
size

Weitere ähnliche Inhalte

Ähnlich wie 1a-OO-Basics.pptx lạoanfanfanfjasnfjnfkaskfklas

Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "
AchrafJbr
 

Ähnlich wie 1a-OO-Basics.pptx lạoanfanfanfjasnfjnfkaskfklas (20)

ppt_ooad.pdf
ppt_ooad.pdfppt_ooad.pdf
ppt_ooad.pdf
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "
 
OOAD chapter 1
OOAD chapter 1 OOAD chapter 1
OOAD chapter 1
 
01 chapter
01 chapter01 chapter
01 chapter
 
Teaching Object Oriented Programming Courses by Sandeep K Singh JIIT,Noida
Teaching Object Oriented Programming Courses by Sandeep K Singh JIIT,NoidaTeaching Object Oriented Programming Courses by Sandeep K Singh JIIT,Noida
Teaching Object Oriented Programming Courses by Sandeep K Singh JIIT,Noida
 
Ooad unit – 1 introduction
Ooad unit – 1 introductionOoad unit – 1 introduction
Ooad unit – 1 introduction
 
Ooad 2
Ooad 2Ooad 2
Ooad 2
 
Ooad
OoadOoad
Ooad
 
Introduction
IntroductionIntroduction
Introduction
 
Intro to oop.pptx
Intro to oop.pptxIntro to oop.pptx
Intro to oop.pptx
 
introduction of Object oriented programming
introduction of Object oriented programmingintroduction of Object oriented programming
introduction of Object oriented programming
 
CPP-Unit 1.pptx
CPP-Unit 1.pptxCPP-Unit 1.pptx
CPP-Unit 1.pptx
 
Software Engineering Lec5 oop-uml-i
Software Engineering Lec5 oop-uml-iSoftware Engineering Lec5 oop-uml-i
Software Engineering Lec5 oop-uml-i
 
Seng 123 8-ooad
Seng 123 8-ooadSeng 123 8-ooad
Seng 123 8-ooad
 
Introducción al Análisis y Diseño Orientado a Objetos
Introducción al Análisis y Diseño Orientado a ObjetosIntroducción al Análisis y Diseño Orientado a Objetos
Introducción al Análisis y Diseño Orientado a Objetos
 
2 uml
2 uml2 uml
2 uml
 
oomd-unit-i-cgpa.ppt
oomd-unit-i-cgpa.pptoomd-unit-i-cgpa.ppt
oomd-unit-i-cgpa.ppt
 
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
 
Oo concepts and class modeling
Oo concepts and class modelingOo concepts and class modeling
Oo concepts and class modeling
 

Kürzlich hochgeladen

Lucknow 💋 High Profile Call Girls in Lucknow - Book 8923113531 Call Girls Ava...
Lucknow 💋 High Profile Call Girls in Lucknow - Book 8923113531 Call Girls Ava...Lucknow 💋 High Profile Call Girls in Lucknow - Book 8923113531 Call Girls Ava...
Lucknow 💋 High Profile Call Girls in Lucknow - Book 8923113531 Call Girls Ava...
anilsa9823
 
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...
anilsa9823
 
Bobbie goods coloring book 81 pag_240127_163802.pdf
Bobbie goods coloring book 81 pag_240127_163802.pdfBobbie goods coloring book 81 pag_240127_163802.pdf
Bobbie goods coloring book 81 pag_240127_163802.pdf
MARIBEL442158
 
Young⚡Call Girls in Lajpat Nagar Delhi >༒9667401043 Escort Service
Young⚡Call Girls in Lajpat Nagar Delhi >༒9667401043 Escort ServiceYoung⚡Call Girls in Lajpat Nagar Delhi >༒9667401043 Escort Service
Young⚡Call Girls in Lajpat Nagar Delhi >༒9667401043 Escort Service
sonnydelhi1992
 
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
anilsa9823
 
Authentic # 00971556872006 # Hot Call Girls Service in Dubai By International...
Authentic # 00971556872006 # Hot Call Girls Service in Dubai By International...Authentic # 00971556872006 # Hot Call Girls Service in Dubai By International...
Authentic # 00971556872006 # Hot Call Girls Service in Dubai By International...
home
 
Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)
Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)
Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)
Business Bay Call Girls || 0529877582 || Call Girls Service in Business Bay Dubai
 
(9711106444 )🫦#Sexy Desi Call Girls Noida Sector 4 Escorts Service Delhi 🫶
(9711106444 )🫦#Sexy Desi Call Girls Noida Sector 4 Escorts Service Delhi 🫶(9711106444 )🫦#Sexy Desi Call Girls Noida Sector 4 Escorts Service Delhi 🫶
(9711106444 )🫦#Sexy Desi Call Girls Noida Sector 4 Escorts Service Delhi 🫶
delhimunirka444
 
FULL NIGHT — 9999894380 Call Girls In Saket | Delhi
FULL NIGHT — 9999894380 Call Girls In Saket | DelhiFULL NIGHT — 9999894380 Call Girls In Saket | Delhi
FULL NIGHT — 9999894380 Call Girls In Saket | Delhi
SaketCallGirlsCallUs
 

Kürzlich hochgeladen (20)

Lucknow 💋 High Profile Call Girls in Lucknow - Book 8923113531 Call Girls Ava...
Lucknow 💋 High Profile Call Girls in Lucknow - Book 8923113531 Call Girls Ava...Lucknow 💋 High Profile Call Girls in Lucknow - Book 8923113531 Call Girls Ava...
Lucknow 💋 High Profile Call Girls in Lucknow - Book 8923113531 Call Girls Ava...
 
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...
 
Bobbie goods coloring book 81 pag_240127_163802.pdf
Bobbie goods coloring book 81 pag_240127_163802.pdfBobbie goods coloring book 81 pag_240127_163802.pdf
Bobbie goods coloring book 81 pag_240127_163802.pdf
 
RAJKOT CALL GIRL 76313*77252 CALL GIRL IN RAJKOT
RAJKOT CALL GIRL 76313*77252 CALL GIRL IN RAJKOTRAJKOT CALL GIRL 76313*77252 CALL GIRL IN RAJKOT
RAJKOT CALL GIRL 76313*77252 CALL GIRL IN RAJKOT
 
Young⚡Call Girls in Lajpat Nagar Delhi >༒9667401043 Escort Service
Young⚡Call Girls in Lajpat Nagar Delhi >༒9667401043 Escort ServiceYoung⚡Call Girls in Lajpat Nagar Delhi >༒9667401043 Escort Service
Young⚡Call Girls in Lajpat Nagar Delhi >༒9667401043 Escort Service
 
Storyboard short: Ferrarius Tries to Sing
Storyboard short: Ferrarius Tries to SingStoryboard short: Ferrarius Tries to Sing
Storyboard short: Ferrarius Tries to Sing
 
AaliyahBell_themist_v01.pdf .
AaliyahBell_themist_v01.pdf             .AaliyahBell_themist_v01.pdf             .
AaliyahBell_themist_v01.pdf .
 
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
 
Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...
Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...
Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...
 
VIP Ramnagar Call Girls, Ramnagar escorts Girls 📞 8617697112
VIP Ramnagar Call Girls, Ramnagar escorts Girls 📞 8617697112VIP Ramnagar Call Girls, Ramnagar escorts Girls 📞 8617697112
VIP Ramnagar Call Girls, Ramnagar escorts Girls 📞 8617697112
 
Authentic # 00971556872006 # Hot Call Girls Service in Dubai By International...
Authentic # 00971556872006 # Hot Call Girls Service in Dubai By International...Authentic # 00971556872006 # Hot Call Girls Service in Dubai By International...
Authentic # 00971556872006 # Hot Call Girls Service in Dubai By International...
 
Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)
Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)
Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)
 
(9711106444 )🫦#Sexy Desi Call Girls Noida Sector 4 Escorts Service Delhi 🫶
(9711106444 )🫦#Sexy Desi Call Girls Noida Sector 4 Escorts Service Delhi 🫶(9711106444 )🫦#Sexy Desi Call Girls Noida Sector 4 Escorts Service Delhi 🫶
(9711106444 )🫦#Sexy Desi Call Girls Noida Sector 4 Escorts Service Delhi 🫶
 
GENUINE EscoRtS,Call Girls IN South Delhi Locanto TM''| +91-8377087607
GENUINE EscoRtS,Call Girls IN South Delhi Locanto TM''| +91-8377087607GENUINE EscoRtS,Call Girls IN South Delhi Locanto TM''| +91-8377087607
GENUINE EscoRtS,Call Girls IN South Delhi Locanto TM''| +91-8377087607
 
Lucknow 💋 Escort Service in Lucknow (Adult Only) 8923113531 Escort Service 2...
Lucknow 💋 Escort Service in Lucknow  (Adult Only) 8923113531 Escort Service 2...Lucknow 💋 Escort Service in Lucknow  (Adult Only) 8923113531 Escort Service 2...
Lucknow 💋 Escort Service in Lucknow (Adult Only) 8923113531 Escort Service 2...
 
FULL NIGHT — 9999894380 Call Girls In Saket | Delhi
FULL NIGHT — 9999894380 Call Girls In Saket | DelhiFULL NIGHT — 9999894380 Call Girls In Saket | Delhi
FULL NIGHT — 9999894380 Call Girls In Saket | Delhi
 
(NEHA) Call Girls Mumbai Call Now 8250077686 Mumbai Escorts 24x7
(NEHA) Call Girls Mumbai Call Now 8250077686 Mumbai Escorts 24x7(NEHA) Call Girls Mumbai Call Now 8250077686 Mumbai Escorts 24x7
(NEHA) Call Girls Mumbai Call Now 8250077686 Mumbai Escorts 24x7
 
Deconstructing Gendered Language; Feminist World-Making 2024
Deconstructing Gendered Language; Feminist World-Making 2024Deconstructing Gendered Language; Feminist World-Making 2024
Deconstructing Gendered Language; Feminist World-Making 2024
 
Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...
Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...
Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...
 
Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...
Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...
Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...
 

1a-OO-Basics.pptx lạoanfanfanfjasnfjnfkaskfklas

  • 2. Introduction to Object Orientation Topics • Overview • Basic Principles of Object Orientation • Basic Concepts of Object Orientation • Strengths of Object Orientation 4/9/2024 2
  • 3. Overview • What are object-oriented (OO) methods? – OO methods provide a set of techniques for analyzing, decomposing, and modularizing software system architectures – In general, OO methods are characterized by structuring the system architecture on the basis of its objects (and classes of objects) rather than the actions it performs • What are the benefits of OO? – OO enhances key software quality factors of a system and its constituent components OO Basics 3
  • 4. OOA, OOD, and OOP • Object-oriented methods may be applied to different phases in the software lifecycle – e.g., analysis, design, implementation, etc. • Object-oriented analysis (OOA) is a process of discovery – models and understands the requirements of the system • Object-oriented design (OOD) is a process of invention and adaptation – creates the abstractions and mechanisms necessary to meet the system's behavioral requirements determined during analysis OO Basics 4
  • 5. Basic Definitions OOD, and OOP • Object-Oriented Design (OOD) – A method for decomposing software architectures based on the objects every system or subsystem manipulates – Rather than "the" function it is meant to ensure • Object-Oriented Programming (OOP) – construction of software systems using object oriented concepts as inheritance, polymorphism, encapsulation, dynamic binding. • Distinguish between OOD and OOP – OOD is relatively independent of the programming language used. – OOP is primarily concerned with programming language and software implementation issues OO Basics 5
  • 6. Object-Oriented Approach • Model objects that are part of the problem • Have objects exhibit their normal behavior • Add objects that do not have problem-space analogs • Have the objects work together to create a solution Design patterns help you identify less-obvious abstractions and the objects that can capture them. - GOF OO Basics 6
  • 7. Five Basic Characteristics of OO "Pure" object-orientation by Alan Kay (Smalltalk): • Everything is an object. • A program is a bunch of objects telling each other what to do by sending messages. • Each object has its own memory made up of other objects. • Every object has a type. • All objects of a particular type can receive the same message. OO Basics 7
  • 8. 4/9/2024 8 Basic Principles of Object Orientation Object Orientation Encapsulation Abstraction Hierarchy Polymorphism
  • 9. What Is Abstraction? • The essential characteristics of an entity that distinguishes it from all other kinds of entities. • Defines a boundary relative to the perspective of the viewer. • Is not a concrete manifestation, denotes the ideal essence of something. 4/9/2024 9 Salesperson: Not saying Which salesperson – just a salesperson in general!!! Customer Product Manages Complexity
  • 10. What Is Encapsulation? • Hides implementation from clients. – Clients depend on interface. 4/9/2024 10 Improves Resiliency
  • 11. Encapsulation • "Encapsulation is a mechanism used to hide the data, internal structure, and implementation details of an object. All interaction with the object is through a public interface of operations." (Craig Larman) • A boundary exists around each object; – the boundary encapsulates the object’s characteristics (data elements) and behaviors (functionality). • The reason for hiding features is to: (1) keep users from touching parts of the object they shouldn’t touch; (2) allows creator of the object to change the object’s internal working without affecting the users of the object. 4/9/2024 11
  • 12. What Is Polymorphism? • The ability to hide many different implementations behind a single interface. 4/9/2024 12 Manufacturer A Manufacturer B Manufacturer C OO Principle: Encapsulation Remote Control
  • 13. Polymorphism • Occurs with inheritance. • Different subclasses may have different implementations of the identical operations • Allows you to treat an object as the base class, rather than as a specific inherited type. • Programmer doesn’t have to keep track of the specific subclasses, the system selects the correct operation based on the object type. • Accomplished at run time using dynamic binding. – lets you substitute objects that have identical interfaces for each other at run-time. 4/9/2024 13
  • 14. What is Hierarchy? 4/9/2024 14 Decreasing abstraction Increasing abstraction Asset RealEstate Savings BankAccount Checking Stock Security Bond Elements at the same level of the hierarchy should be at the same level of abstraction Levels of abstraction
  • 15. Basic Concepts of Object Orientation • Object • Class • Attribute • Operation • Interface • Package • Relationships 4/9/2024 15
  • 16. What is an Object? • Informally, an object represents an entity, either physical, conceptual, or software – Physical entity – Conceptual entity – Software entity 4/9/2024 16 Truck Chemical Process Linked List
  • 17. A More Formal Definition • An object is a concept, abstraction, or thing with sharp boundaries and meaning for an application • An object is something that has: – State – Behavior – Identity 4/9/2024 17
  • 18. What is a Class? • A class is a description of a group of objects with common properties (attributes), behavior (operations), relationships, and semantics – An object is an instance of a class • A class is an abstraction in that it: – Emphasizes relevant characteristics – Suppresses other characteristics 4/9/2024 18 OO Principle: Abstraction
  • 19. 4/9/2024 19 Sample Class a + b = 10 Class Course Properties Name Location Days offered Credit hours Start time End time Behavior Add a student Delete a student Get course roster Determine if it is full
  • 20. Representing Classes in the UML • A class is represented using a rectangle with three compartments: – The class name – The structure (attributes) – The behavior (operations) 4/9/2024 20 Professor - name - employeeID : UniqueId - hireDate - status - discipline - maxLoad + submitFinalGrade() + acceptCourseOffering() + setMaxLoad() + takeSabbatical() + teachClass()
  • 21. Classes of Objects • How many classes do you see? 4/9/2024 21
  • 22. Classes and Objects Relationship • A class is an abstract definition of an object – It defines the structure and behavior of each object in the class – It serves as a template for creating objects • Objects are grouped into classes 4/9/2024 22 Objects Class Professor Smith Professor Jones Professor Mellon Professor
  • 23. What Is an Attribute? • An attribute is a named property of a class that describes the range of values that instances of the property may hold. – A class may have any number of attributes or no attributes at all. 4/9/2024 23 Attributes Student - name - address - studentID - dateOfBirth
  • 24. What Is an Operation? • A service that can be requested from an object to effect behavior. An operation has a signature, which may restrict the actual parameters that are possible. • A class may have any number of operations or none at all. 4/9/2024 24 Operations Student + get tuition() + add schedule() + get schedule() + delete schedule() + has prerequisites()
  • 25. What is an Interface? • Interfaces formalize polymorphism • Interfaces support “plug-and-play” architectures 4/9/2024 25 Tube Pyramid Cube Shape Draw Move Scale Rotate <<interface>> Realization relationship (stay tuned for realization relationships)
  • 26. Interface • How do you get an object to do useful work for you? • Objects are known only through their interfaces • Every object presents an interface to the world. • Interface determines what you can get an object to do. • Represent a "contract" with other objects. • Communicate with objects by sending messages to them; an object’s interface is the set of messages an object will respond to. 4/9/2024 26
  • 27. What is a Package? • A package is a general purpose mechanism for organizing elements into groups • A model element which can contain other model elements • Uses – Organize the model under development – A unit of configuration managemen 4/9/2024 27 Package Name
  • 28. Relationships • Association – Aggregation • Dependency • Inheritance • Realization 4/9/2024 28 ConsoleWindow Window open() close() move() display() handleEvent() Event DialogBox Control association generalization
  • 29. Relationships: Association • Models a semantic connection among classes 4/9/2024 29 Professor University Works for Class Association Association Name
  • 30. Relationships: Association Aggregation • To model a “whole/part” relationship, use aggregation. • Aggregation represents a “has-a” or “is a part-of” relationship, meaning that an object of the whole has objects of the part. [Martin Fowler] 30 4/9/2024 Company Department * 1
  • 31. Association: Multiplicity and Navigation • Multiplicity defines how many objects participate in a relationships – Specified for each end of the association • Associations are bi-directional by default, but it is often desirable to restrict navigation to one direction 4/9/2024 31 Customer Account 1 0..* Multiplicity Navigation
  • 32. Relationships: Dependency • A relationship between two model elements where a change in one may cause a change in the other – E.g. Class A depends on class B: method of A manipulates objects of B in the parameters, local variables, or return types 4/9/2024 32 Package ClientPackage SupplierPackage Client Supplier Class Dependency relationship
  • 36. What Gets Inherited? • A subclass inherits its parent’s attributes, operations, and relationships • A subclass may: – Add additional attributes, operations, relationships – Redefine inherited operations (use caution!) • Common attributes, operations, and/or relationships are shown at the highest applicable level in the hierarchy 4/9/2024 36 Inheritance leverages the similarities among classes
  • 37. 4/9/2024 37 Example: What Gets Inherited Truck tonnage GroundVehicle weight licenseNumber Car owner register( ) getTax( ) Person 0..* Trailer 1 Superclass (parent) Subclass generalization size