04 Concept Object Oriented
04 Concept Object Oriented
Objectives
Object
Class
Inheritance
Single Inheritance
Multiple Inheritance
Polymorphism
11
1
2025/3/27
12
What is an object?
Anobject is a meaningful thing in the application
domain. It can be a physical entity or a concept.
Physical Entity
Concept
Chemical Process
13
2
2025/3/27
Properties of an object
Identity
Each object must have a name to distinguish it from
other objects
“Identifiers” are used to accomplish this task in a program
State
Use the state (or attributes) to describe certain
characteristics of an object
Use "variables" (which can be simple or complex) to
accomplish this task
Behavior it might be another object
14
Identity
Each object has a unique identifier to distinguish it from
other objects, even if its state may be the same as that
of other objects.
TV,No. 1, Row 1
TV,No. 2, Row 1
TV11
TV,No. 3, Row 1
TV12
TV13
15
3
2025/3/27
State
It is all values possessed by each attribute at a
certain moment
Student
NO, set, age, grade, scores, etc.
TV
color, volume, brightness, channel, system, etc.
The "grade" attribute of a student will change according
to whether the student is promoted to the next grade or
retained in the current grade
The “channel” attribute of a TV will change according to
the choice of the person watching TV.
16
behavior
When other objects send requests, the object responds
in a certain way.
17
4
2025/3/27
adjustVolume
color
brightness
volume
channel
system
18
Interaction of objects
An object that is completely isolated is of no use
Thereshould be interactions among objects when the
system is running.
How to accomplish the interactions of objects?
message passing
A message is the request information sent by the
sending object to the receiving object to invoke a
behavior of receiving object, and when necessary, it
includes the information of appropriate parameter
Composition of the message
Identity of receiving object
Name of the invoked operation(function, behavior)
arguments
19
5
2025/3/27
Interaction of objects
adjustVolume
color
Receiving
Object brightness
Name of
operation
volume
arguments
channel
system
TV12 adjustChannel Up
TV12
20
Properties of Message
The same object can receive multiple messages in different
forms and make different responses.
“TV11 adjustChannel down”
“TV11 adjustVolume louder”
“TV11 adjustColor intense”
Messages in the same form can be sent to different objects,
and the responses they elicit can vary
“TV11 adjustChannel up”(from 15 to 16)
“TV12 adjustChannle up”(from 5to 6)
The sending of a message does not need to take the specific
recipient into account. An object may or may not respond to a
message.
message multicast
21
6
2025/3/27
Concept of a class
A class is a collection of objects that have the same data
composition and the same behavior.
color adjustColor
volume adjustVolume
system adjustSystem
channel adjustChannel
brightness adjustBrightness
open
close
TV
22
23
7
2025/3/27
Data Encapsulation
24
Data Abstraction
An object is an abstraction of an entity in the real
world
Abstraction is a kind of simplified description
It emphasizes the characteristics relevant to the
given application.
It suppresses the irrelevant characteristics.
A class is an abstraction of a group of objects
25
8
2025/3/27
Encapsulation
A class is divided into two parts: the interface and the implementation.
For users, the interface is visible, while the implementation is invisible
Only the operations provided by the class can modify the attribute
values.
Hiding the implementation details of a class is called encapsulation.
implementation
interface balance
interestYTD
makeDeposit owner
User withdraw account_number
transfer makeDeposit
withDraw
transfer
an impenetrable wall
26
Advantages of encapsulation
two types of protection
Protect objects from being misused by users.
Users have no right to access implementation, such as attribute
values and operation processes.
Protect client - side code when the implementation of an
object changes.
Changes in the object's implementation do not affect the client -
side code.
27
9
2025/3/27
28
Inheritance
Superclass and Subclass
Multiple Inheritance
29
10
2025/3/27
Superclass Electronic
30
31
11
2025/3/27
32
Rectangle Triangle
Length
Width
Diagonal
Square
33
12
2025/3/27
34
Advantages of Inheritance
Increase the opportunities for software reuse.
Reduce development and maintenance costs.
Develop a model that is closer to reality.
Make the system more flexible.
All subclasses automatically inherit the changes of the
superclass.
Deal with changes in requirements by adding a subclass.
Ensure consistency among classes.
The superclass can customize rules for all subclasses.
Inherit the interface and implementation.
Support polymorphism.
37
13