SlideShare a Scribd company logo
1 of 28
Introduction to
Object Oriented Programming
• The goals:
– Understand the concept of
1. object,
2. class,
3. attribute,
4. operation,
5. constructor,
6. accessor and mutator,
7. visibility, and
8. encapsulation and information hiding.
– Able to build algorithm using OOP
• We can distinguish the
following learning curve of
someone who learns to
program:
1. unstructured
programming,
2. modular programming,
and
3. object-oriented
programming.
What is OOP?
• In old style (unstructured and modular)
programming, you had:
– data, which was completely passive
– functions, which could manipulate any data.
• Meanwhile, in OOP you will have:
– Objects and
– communication among objects.
1. OBJECT
• An object contains both
data and methods that
manipulate that data
– An object is active, not
passive; it does things
– An object is responsible for its
own data
• But: it can expose that data to
other objects
• Each object can be viewed as an independent
machine with a distinct role or responsibility.
Operations are closely associated with the objects,
carry their own operators around with them.
2. CLASS
• An object contains both
data and methods that
manipulate that data
– An object is active, not
passive; it does things
– An object is responsible for its
own data
• But: it can expose that data to
other objects
• Each object can be viewed as an independent
machine with a distinct role or responsibility.
Operations are closely associated with the objects,
carry their own operators around with them.
Classes and Objects
Object
<7_series_BMW>
Object
<Ford_Mustang>
Object
<VW_Beetle>
Class
<CAR>
Objects
• The term object is not easily defined
• According to Webster:
– Object: a visible or tangible thing of relative
stable form; A thing that may be apprehended
intellectually; A thing to which thought or action is
directed
• In this class, we will use the following
definition:
– An object has state, behavior, and identity (Booch)
State
• The state of an object
encompasses all of the (static)
properties of the object plus the
current (dynamic) values of each
of these properties
• A property is an inherent or
distinctive characteristic, trait,
quality, or feature that contribute
to making an object uniquely that
object
• We will use the word attribute, or
data member, to refer to the
state of an object
• State of the object
Ford_Mustang is THIS
COOL LOOKING RED
Ford_Mustang.
• A property of THIS
Mustang is its Color.
• Attribute is another
name for the property
e.g. color.
Examples
• Properties ( Attributes ) :
– Elevators travel up or down
– Vending machines accept coins
– Clocks indicate the current time
• Values
– Current floor
– Number of coins deposited
– The number of minutes since the last hour
Messages to Objects
Object
<7_series_BMW>
“Start the
engine of the
BMW”
Start_Engine
Method of a Class
Class
<CAR>
Start_Engine
Behavior
• Behavior is how an object acts and reacts, in
terms of state changes and interactions with
other objects.
• An operation is some action that one object
performs upon another in order to elicit a
reaction.
• We will use the word method to describe
object behavior in java.
• Invoking a method causes the behavior to take
place.
Types of Methods
• There are 4 basic types of methods:
– Modifier (sometimes called a mutator)
• Changes the value associated with an attribute of the object
• E.g. A method like Change_Car_Color
– Accessor
• Returns the value associated with an attribute of the object
• E.g. A method like Price_of_Car
– Constructor
• Called once when the object is created (before any other method will
be invoked)
• E.g. Car(Mustang)
– Destructor
• Called when the object is destroyed
• E.g.~Car( )
Identity
• Identity is the property of an object that
distinguishes it from all other objects.
• The failure to recognize the difference
between the name of the object and the
object itself is the source of many errors in
object-oriented (OO) programming.
Assignment and Equality
• What does it mean to assign one object to another?
– Copy the name only (shallow copy)
– Duplicate the object, creating a different object (with a
different name) whose state and behavior is the same as
the original (deep copy)
• Equality like assignment, can mean two things
– Two names designate the same object
– Two objects are different but their state and behavior are
the same
Relationships
• Objects contribute to the behavior of a system by
collaborating with one another
– A car is a collection of parts like the Engine, Steering
Wheel, Wipers,Wheels each sending messages to each
other so that the car can be driven!!
• The relationship between any two objects
encompasses the assumptions that each makes
about the other, including what operations can be
performed and what behavior results from it.
Relationships
• There are two kinds of relationships that are
of particular interest.
– Using relationship
• E.g. Owner uses the Car.
– Containing relationship
• E.g. Car contains an Engine
Therefore a Class is?
• According to Webster
– A group, set, or kind marked by common
attributes or a common attribute
• A class is a set of objects that share a common
structure and a common behavior
– An object is a concrete entity that exists in space
and time, an instance of a class
– A class represents only an abstraction, the essence
of an object from the class
Class
• A class can be thought of as a cookie cutter, form
which objects can be instantiated
– A class is to an object, as a blueprint is to a building
• The class mammal represents the characteristics
common to all mammals
– Live birth, nurse young, have hair, …
• “Paul”, “PJ”, “Lisa”, “Heidi”, and “James” are specific
instances from the class mammal
Class Relationships
• Consider for a moment the following classes
– Flowers
– Daisies
– Red roses
– Yellow roses
– Petals
• What observations can you make?
Kinds of Relationships
• Classes, like objects, do not exist in isolation.
• Relations between classes can be made for
one of two reasons.
– To indicate some sort of sharing.
• A yellow rose and a red rose are both roses and have
petals, roots, leaves, thorns, etc.
– Some kind of semantic connection.
• Daisies and roses are both flowers that are pollinated in
the same way.
Kinds of Class Relationships
• There are three basic kinds of class relationships
– Generalization (“kind of”)
• A rose is a kind-of a flower
• Generalization provides the ability to create subclasses
• Subclasses share the structure of the parent class
– Aggregation (“part of”)
• A petal is part-of a rose
• Aggregation allows one to construct new classes from existing one
– Association
Inheritance
• The term, inheritance, is used in many object
oriented (OO) programming languages to
describe the generalization relationship
• Inheritance is a relationship where one class
shares the structure or behavior defined in
one class (single inheritance) or more
(multiple inheritance)
Types of Inheritance
Form of Inheritance
Description
Specification The superclass defines behavior that is implemented in the
subclass but not in the superclass. Provides a way to
guarantee that subclass implement the same behavior.
Specialization The subclass is a specialized form of the superclass but
satisfies the specifications of the parent class in all relevant
aspects.
Extension The subclass adds new functionality to the parent
class, but does not change any inherited behavior.
Limitation The subclass restricts the use of some of the behavior
inherited from the superclass.
Combination The subclass inherits features from more than one
superclass (i.e. multiple inheritance).
Benefits of Inheritance
• One view of inheritance is that it provides a
way to specify some properties/behaviors that
all subclasses must exhibit
• Inheritance can be used to re-use code
• Inheritance also provides the ability to
generalize
– A method can be written to work with the super-
class but subclasses can be passed as arguments
Views of a Class
• A class can be viewed as a sort of contract that
specifies what instances of the class can, and
cannot do
• It is possible to distinguish between the
outside and inside view of a class
• The interface of a class provides its outside
view and emphasizes the abstraction
• The implementation of a class is its inside view
Access
• Most classes provide three levels of access to their
members (state and behavior):
– Public
• The part of the class of the class that is visible to all clients of the
class
– Protected
• The part of the class that is only visible to subclasses of the class
– Private
• A part of the class that is not visible to any other classes

More Related Content

What's hot

Object Oriented Analysis And Design
Object Oriented Analysis And DesignObject Oriented Analysis And Design
Object Oriented Analysis And Design
Sahil Mahajan
 
Polishing Diamonds In Owl2 Ekaw 2008 Acitrezza
Polishing Diamonds In Owl2 Ekaw 2008 AcitrezzaPolishing Diamonds In Owl2 Ekaw 2008 Acitrezza
Polishing Diamonds In Owl2 Ekaw 2008 Acitrezza
Rinke Hoekstra
 

What's hot (20)

Ooadb
OoadbOoadb
Ooadb
 
enhanced er diagram
enhanced er diagramenhanced er diagram
enhanced er diagram
 
Software enginering.group-no-11 (1)
Software enginering.group-no-11 (1)Software enginering.group-no-11 (1)
Software enginering.group-no-11 (1)
 
Object orientation
Object orientationObject orientation
Object orientation
 
Introduction of object oriented analysis &amp; design by sarmad baloch
Introduction of object oriented analysis &amp; design by sarmad balochIntroduction of object oriented analysis &amp; design by sarmad baloch
Introduction of object oriented analysis &amp; design by sarmad baloch
 
0-oop java-intro
0-oop java-intro0-oop java-intro
0-oop java-intro
 
Object Oriented Analysis And Design
Object Oriented Analysis And DesignObject Oriented Analysis And Design
Object Oriented Analysis And Design
 
Data Models
Data ModelsData Models
Data Models
 
Abstraction1
Abstraction1Abstraction1
Abstraction1
 
ER-Model-ER Diagram
ER-Model-ER DiagramER-Model-ER Diagram
ER-Model-ER Diagram
 
Unit 4
Unit 4Unit 4
Unit 4
 
Object oriented modeling
Object oriented modelingObject oriented modeling
Object oriented modeling
 
Polishing Diamonds In Owl2 Ekaw 2008 Acitrezza
Polishing Diamonds In Owl2 Ekaw 2008 AcitrezzaPolishing Diamonds In Owl2 Ekaw 2008 Acitrezza
Polishing Diamonds In Owl2 Ekaw 2008 Acitrezza
 
2 er
2 er2 er
2 er
 
SAD02 - Object Orientation
SAD02 - Object OrientationSAD02 - Object Orientation
SAD02 - Object Orientation
 
encapsulation and abstraction
encapsulation and abstractionencapsulation and abstraction
encapsulation and abstraction
 
Ooad
OoadOoad
Ooad
 
Javasession8
Javasession8Javasession8
Javasession8
 
Big Challenges in Data Modeling: Supertyping and Subtyping
Big Challenges in Data Modeling: Supertyping and SubtypingBig Challenges in Data Modeling: Supertyping and Subtyping
Big Challenges in Data Modeling: Supertyping and Subtyping
 
Enhanced entity relationship model
Enhanced entity relationship modelEnhanced entity relationship model
Enhanced entity relationship model
 

Similar to 07 intro2 oop

Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "
AchrafJbr
 
IBM OOAD Part1 Summary
IBM OOAD Part1 SummaryIBM OOAD Part1 Summary
IBM OOAD Part1 Summary
Haitham Raik
 

Similar to 07 intro2 oop (20)

Objects and Classes.pptx
Objects and Classes.pptxObjects and Classes.pptx
Objects and Classes.pptx
 
Objects and Classes.pptx
Objects and Classes.pptxObjects and Classes.pptx
Objects and Classes.pptx
 
Objects and Classes BRIEF.pptx
Objects and Classes BRIEF.pptxObjects and Classes BRIEF.pptx
Objects and Classes BRIEF.pptx
 
Ooad ch 2
Ooad ch 2Ooad ch 2
Ooad ch 2
 
Ooad ch 1_2
Ooad ch 1_2Ooad ch 1_2
Ooad ch 1_2
 
Oo concepts and class modeling
Oo concepts and class modelingOo concepts and class modeling
Oo concepts and class modeling
 
MODELLING WITH OBJECTS.pptx
MODELLING WITH OBJECTS.pptxMODELLING WITH OBJECTS.pptx
MODELLING WITH OBJECTS.pptx
 
L1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdfL1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdf
 
Handout on Object orienetd Analysis and Design
Handout on Object orienetd Analysis and DesignHandout on Object orienetd Analysis and Design
Handout on Object orienetd Analysis and Design
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "
 
Ooad unit – 1 introduction
Ooad unit – 1 introductionOoad unit – 1 introduction
Ooad unit – 1 introduction
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
 
IBM OOAD Part1 Summary
IBM OOAD Part1 SummaryIBM OOAD Part1 Summary
IBM OOAD Part1 Summary
 
UML-class_diagram.ppt
UML-class_diagram.pptUML-class_diagram.ppt
UML-class_diagram.ppt
 
UML-class diagram for beginners to adance.ppt
UML-class diagram for beginners to adance.pptUML-class diagram for beginners to adance.ppt
UML-class diagram for beginners to adance.ppt
 
O6u CS-315A OOP Lecture (1).pdf
O6u CS-315A OOP Lecture (1).pdfO6u CS-315A OOP Lecture (1).pdf
O6u CS-315A OOP Lecture (1).pdf
 
[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects
 
DISE - OOAD Using UML
DISE - OOAD Using UMLDISE - OOAD Using UML
DISE - OOAD Using UML
 
Object oriented programming 6 oop with c++
Object oriented programming 6  oop with c++Object oriented programming 6  oop with c++
Object oriented programming 6 oop with c++
 

Recently uploaded

Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
SofiyaSharma5
 
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
anilsa9823
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
ellan12
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 

Recently uploaded (20)

Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 

07 intro2 oop

  • 2. • The goals: – Understand the concept of 1. object, 2. class, 3. attribute, 4. operation, 5. constructor, 6. accessor and mutator, 7. visibility, and 8. encapsulation and information hiding. – Able to build algorithm using OOP
  • 3. • We can distinguish the following learning curve of someone who learns to program: 1. unstructured programming, 2. modular programming, and 3. object-oriented programming.
  • 4. What is OOP? • In old style (unstructured and modular) programming, you had: – data, which was completely passive – functions, which could manipulate any data. • Meanwhile, in OOP you will have: – Objects and – communication among objects.
  • 5. 1. OBJECT • An object contains both data and methods that manipulate that data – An object is active, not passive; it does things – An object is responsible for its own data • But: it can expose that data to other objects • Each object can be viewed as an independent machine with a distinct role or responsibility. Operations are closely associated with the objects, carry their own operators around with them.
  • 6. 2. CLASS • An object contains both data and methods that manipulate that data – An object is active, not passive; it does things – An object is responsible for its own data • But: it can expose that data to other objects • Each object can be viewed as an independent machine with a distinct role or responsibility. Operations are closely associated with the objects, carry their own operators around with them.
  • 8. Objects • The term object is not easily defined • According to Webster: – Object: a visible or tangible thing of relative stable form; A thing that may be apprehended intellectually; A thing to which thought or action is directed • In this class, we will use the following definition: – An object has state, behavior, and identity (Booch)
  • 9. State • The state of an object encompasses all of the (static) properties of the object plus the current (dynamic) values of each of these properties • A property is an inherent or distinctive characteristic, trait, quality, or feature that contribute to making an object uniquely that object • We will use the word attribute, or data member, to refer to the state of an object • State of the object Ford_Mustang is THIS COOL LOOKING RED Ford_Mustang. • A property of THIS Mustang is its Color. • Attribute is another name for the property e.g. color.
  • 10. Examples • Properties ( Attributes ) : – Elevators travel up or down – Vending machines accept coins – Clocks indicate the current time • Values – Current floor – Number of coins deposited – The number of minutes since the last hour
  • 11. Messages to Objects Object <7_series_BMW> “Start the engine of the BMW” Start_Engine
  • 12. Method of a Class Class <CAR> Start_Engine
  • 13. Behavior • Behavior is how an object acts and reacts, in terms of state changes and interactions with other objects. • An operation is some action that one object performs upon another in order to elicit a reaction. • We will use the word method to describe object behavior in java. • Invoking a method causes the behavior to take place.
  • 14. Types of Methods • There are 4 basic types of methods: – Modifier (sometimes called a mutator) • Changes the value associated with an attribute of the object • E.g. A method like Change_Car_Color – Accessor • Returns the value associated with an attribute of the object • E.g. A method like Price_of_Car – Constructor • Called once when the object is created (before any other method will be invoked) • E.g. Car(Mustang) – Destructor • Called when the object is destroyed • E.g.~Car( )
  • 15. Identity • Identity is the property of an object that distinguishes it from all other objects. • The failure to recognize the difference between the name of the object and the object itself is the source of many errors in object-oriented (OO) programming.
  • 16. Assignment and Equality • What does it mean to assign one object to another? – Copy the name only (shallow copy) – Duplicate the object, creating a different object (with a different name) whose state and behavior is the same as the original (deep copy) • Equality like assignment, can mean two things – Two names designate the same object – Two objects are different but their state and behavior are the same
  • 17. Relationships • Objects contribute to the behavior of a system by collaborating with one another – A car is a collection of parts like the Engine, Steering Wheel, Wipers,Wheels each sending messages to each other so that the car can be driven!! • The relationship between any two objects encompasses the assumptions that each makes about the other, including what operations can be performed and what behavior results from it.
  • 18. Relationships • There are two kinds of relationships that are of particular interest. – Using relationship • E.g. Owner uses the Car. – Containing relationship • E.g. Car contains an Engine
  • 19. Therefore a Class is? • According to Webster – A group, set, or kind marked by common attributes or a common attribute • A class is a set of objects that share a common structure and a common behavior – An object is a concrete entity that exists in space and time, an instance of a class – A class represents only an abstraction, the essence of an object from the class
  • 20. Class • A class can be thought of as a cookie cutter, form which objects can be instantiated – A class is to an object, as a blueprint is to a building • The class mammal represents the characteristics common to all mammals – Live birth, nurse young, have hair, … • “Paul”, “PJ”, “Lisa”, “Heidi”, and “James” are specific instances from the class mammal
  • 21. Class Relationships • Consider for a moment the following classes – Flowers – Daisies – Red roses – Yellow roses – Petals • What observations can you make?
  • 22. Kinds of Relationships • Classes, like objects, do not exist in isolation. • Relations between classes can be made for one of two reasons. – To indicate some sort of sharing. • A yellow rose and a red rose are both roses and have petals, roots, leaves, thorns, etc. – Some kind of semantic connection. • Daisies and roses are both flowers that are pollinated in the same way.
  • 23. Kinds of Class Relationships • There are three basic kinds of class relationships – Generalization (“kind of”) • A rose is a kind-of a flower • Generalization provides the ability to create subclasses • Subclasses share the structure of the parent class – Aggregation (“part of”) • A petal is part-of a rose • Aggregation allows one to construct new classes from existing one – Association
  • 24. Inheritance • The term, inheritance, is used in many object oriented (OO) programming languages to describe the generalization relationship • Inheritance is a relationship where one class shares the structure or behavior defined in one class (single inheritance) or more (multiple inheritance)
  • 25. Types of Inheritance Form of Inheritance Description Specification The superclass defines behavior that is implemented in the subclass but not in the superclass. Provides a way to guarantee that subclass implement the same behavior. Specialization The subclass is a specialized form of the superclass but satisfies the specifications of the parent class in all relevant aspects. Extension The subclass adds new functionality to the parent class, but does not change any inherited behavior. Limitation The subclass restricts the use of some of the behavior inherited from the superclass. Combination The subclass inherits features from more than one superclass (i.e. multiple inheritance).
  • 26. Benefits of Inheritance • One view of inheritance is that it provides a way to specify some properties/behaviors that all subclasses must exhibit • Inheritance can be used to re-use code • Inheritance also provides the ability to generalize – A method can be written to work with the super- class but subclasses can be passed as arguments
  • 27. Views of a Class • A class can be viewed as a sort of contract that specifies what instances of the class can, and cannot do • It is possible to distinguish between the outside and inside view of a class • The interface of a class provides its outside view and emphasizes the abstraction • The implementation of a class is its inside view
  • 28. Access • Most classes provide three levels of access to their members (state and behavior): – Public • The part of the class of the class that is visible to all clients of the class – Protected • The part of the class that is only visible to subclasses of the class – Private • A part of the class that is not visible to any other classes