Professional Documents
Culture Documents
Lecture 05a:
Object-Oriented
Concept
1
Objectives
In this lecture you will learn, the
fundamental concepts of object-orientation.
i. Classes and objects
ii. Attributes
iii. Operations, methods and services
iv. Messages
v. Relationships : Inheritance, Association &
Aggregation
vi. Encapsulation, and polymorphism.
4
It Knows things (attributes)
I am an Employee.
I know my name,
IC number and
my address.
I am a Fish. I am a Car.
I know my date of I know my color,
arrival and manufacturer, cost,
expiration. owner and model.
5
It does things (methods)
I know how to
compute
my payroll.
I know how
to cook myself.
I know how to
stop.
6
Class Diagram
7
Object is whatever an application wants to talk
about.
For example, Parts and assemblies might
be objects in material applications.
9
Conceptually, each object is
responsible for itself
A window object is
responsible for things like
opening, sizing, and closing
itself.
System ABC
Object- Object-x
Object- Object-
11
Object-
Traditional Approach
12
OO Approach
Object- Object-x
Object- Object-
Object-
13
Object’s Attributes
15
Object (taken from G. Booch, 1994)
16
Roles and Responsibilities
(Grady Booch, 2007)
OOSD 17
Class
19
Employee Class
Salesman
Manager Accountant
B o e in g A i r p l a n e O b j e c ts
( B o e in g in s ta n c e s )
17-
22
Oct-22
Class (Taken from G. Booch, 1994)
23
Relationships
3 types
Inheritance
Association
Aggregation
24
Inheritance - Class hierarchy
25
A subclass inherits all of the properties
and methods (procedures) defined in its
superclass.
Motor Vehicle
17-
26
Oct-22
Inheritance
27
V ehicle
C ar
I know how to stop
stop m ethod is reusable
F ord
stop (m yM ustang)
28
Multiple inheritance
29
For example utility vehicle inherits from
Car and Truck classes.
MotorVehicle
UtilityVehicle
30
(taken from G. Booch, 1994)
31
Associations
32
Aggregation
Aggregation is defined as a special form of
association that specifies a whole-part
relationship between the aggregate (the whole)
and the component part (the part) (Jacobson,
1999)
33
For example, the class family (the whole)
is made out of class children and class
parent (the parts), as shown in the Figure
below.
Family
Parent Children
34
Encapsulation and Information Hiding
Permissible operations
Messages
Yolk (data)
Data
white (process)
Private Protocol shell (interface)
Public Protocol Figure Objects represented by an egg [Avison]
35
C++ has a general encapsulation protection
mechanism:
public - may be accessed from any other classes
private - accessible only from within the class itself
protected - can be accessed only from subclasses
Encapsulation in Python:
https://pythonspot.com/encapsulation/
Often, an object is said to encapsulate the data.
This is to ensure that no object can operate directly
on another object’s data.
36
Examples
38
Message
Message is defined as a specification of a
communication between objects that conveys
information with the expectation that an
activity will happen (Jacobson et al., 1999).
39
Example
Course
Student registerCourse
+registerCourse()
+displayDetails()
40
Method & message
(taken from G. Booch, 1994)
41
A Case study – A payroll program
Consider a payroll program that processes
employee records at a small manufacturing
firm. This company has three types of
employees:
44
FOR EVERY EMPLOYEE DO
BEGIN
IF employee = manager THEN
CALL computeManagerSalary
IF employee = office worker THEN
CALL computeOfficeWorker_salary
IF employee = production worker THEN
CALL computeProductionWorker_salary
IF employee = temporary office worker THEN
CALL computeTemporaryOfficeWorkerSalary
IF employee = junior production worker THEN
CALL computeJuniorProductionWorkerSalary
END 17-
45
Oct-22
An OO Approach
What objects does the application need?
The goal of OO analysis is to identify objects
and classes that support the problem
domain and system's requirements.
Some general candidate classes are:
Persons
Places
Things
46
What are some of the application’s
classes?
Employee
Manager
Office Workers
Production Workers
47
Class hierarchy
48
Employee
name
address
salary
SS#
50
If a new class of employee
were added E m p lo y e e
nam e
a d d re ss
sa la ry
SS#
T e m p o ra ry O ffic e W o rk er J u n io rP ro d u c tio n W o rk e r
C o m p u te P a y ro ll C o m p u te P a y ro ll
51
Polymorphism
52
polymorphism example
For example, consider method
draw graph in objects line graph,
histogram and pie chart.
53
Objects and Persistence
54
Summary
?
56