Professional Documents
Culture Documents
1
Outline
• Introduction to OOAD
• OOP
• Basic Principles of Object Orientation
• Objects and classes
• Components and packages
• Abstraction, encapsulation
• ER and EER, inheritance
• Polymorphism
• Benefits of OOAD
• Comparison of OOAD and structures
2
OOAD
• It focuses on objects where system is
broken down in terms of the objects that
exist within it.
3
Object Oriented Programming
• Programming using objects
• An object represents an entity
– Real world object: car, watch, …
– Abstract object: network connection, …
Object Orientation
Encapsulation
Abstraction
Modularity
Hierarchy
5
Objects
• Definition: An object is a software bundle that has
State and Behavior.
– state – properties of the object
– behavior – operations the object can perform
• Person Example:
– State: Height, weight, gender, age
– Behavior: Eat, sleep, exercise, study
7
Objects (more)
Object Identity Behaviors State
8
Representing Objects
• An object is represented as a rectangle with
underlined name
(unnamed object)
Professor
a + b = 10
ProfessorSelam
Class Name Only
Professor Selam
Professor: Object Name Only
ProfessorSelam:
10
Representing Classes
• A class is represented using a compartmented rectangle
– (note: no underlining)
a + b = 10
Professor
Professor Selam
11
Class Compartments
• A class is comprised of three sections:
– The first section contains the class name
– The second section shows the state (attributes)
– The third section shows the behavior (operations)
12
The Relationship Between Classes and
Objects
• A class is an abstract definition of an object
– It defines the state and behavior of each object in the
class
– It serves as a template for creating objects
Objects Class
Professor
Professor Kidist
13
What is an Attribute?
Object
Class
Specific
Attribute attribute values
:CourseOffering
for different
objects coursenumber = 101
startTime = 9:00
CourseOffering endTime = 11:00
coursenumber
startTime
endTime :CourseOffering
coursenumber = 104
startTime = 13:00
endTime = 15:00
Attribute: data items that define
object.
14
What is an Operation?
CourseOffering
Class
addStudent
deleteStudent
getStartTime
Operation getEndTime
15
Employee object & class
Class Object
Employee Employee16
name: string name: Abe
address: string address: Mekelle
dateOfBirth: Date dateOfBirth: 02/10/85
employeeNo: integer employeeNo: 324
socialSecurityNo: string socialecurityNo:E342545
department: Dept department: Sale
ma nager: Employee manager: Employee1
salary: integer salary: 2340
status: {current, left, retired} stauts:current
taxCode: integer taxCode: 3432
. .. ….
join () Eployee16.join(02/05/1997)
leave ()
retire () Eployee16.retire(03/08/2005)
changeDetails () Eployee16.changeDetail(“X
16
Street No. 12”)
Person Example
class Person {
String name = "Jamal";
int age = 26;
String getName() { return name; }
19
BankAccount Example
…
double deposit(double amount) {
balance += amount;
return balance;
}
boolean withdraw(double amount) {
if (amount < balance) {
balance -= amount;
return true;
} else return false;
}
}// End BankAccount Class
20
What is a Component?
• A non-trivial, nearly independent, and replaceable part of
a system that fulfills a clear function in the context of a
well-defined architecture
• A component may be
– A source code component
– A run time component or
– An executable component OO Principle:
Encapsulation
• Ex: in the Java API, similar classes are available in ‘packages’ that
we may import, etc.
OO Principle:
Package Name Modularity
• Uses
– Organize the model under development
– A unit of configuration management
23
What is Abstraction?
• Procedure abstraction- is to divide a single
problem to many simple sub-tasks.
• Data abstraction is to collect essential
elements composing to a compound data.
Phone
• Objective: Properties:
Manufacturer
– Reusable Type
– Replaceable Opening
– Manages complexity mechanism
24
Abstraction…
Salesperson
Not saying which
salesperson – just
a salesperson in
general!!
Product
Customer
Manages Complexity
25
What is Encapsulation?
• Hide implementation details from clients
– Clients depend on interface – only!
– Clients do not need to know ‘how’ the server operates
or provides the services!
27
Encapsulation…
private attributes and methods are encapsulated within
the class, they cannot be seen by clients of the class
public methods define the interface that the class
provides to its clients
Customer
- numCustomers = 0
private attributes - MIN_BUDGET = 200
- name: String
- address: String
- budget: int
Customer class
28
What is Modularity?
• The breaking up of something complex system
into manageable pieces
Personal info.
of employee
Employee DB Can be
divided into
Payroll system
Manages Complexity
29
Object communication
• Objects communicate with each other by
sending messages
– a message is a method call from a message-
sending object to a message-receiving object
– a message consists of
• an object reference which indicates the message receiver
• a method name (corresponding to a method of the
receiver), and
• parameters (corresponding to the arguments of the calling
method)
– a message-receiving object is a server to a
message-sending object, and
– the message-sending object is a client of the server
30
Message Passing
Customer SalesPerson
- numCustomers = 0
- MAX_ PRICE = 200
- MIN_BUDGET = 200
- name: String
- name: String
- employeeNo: String
- address: String
- commission: int
- budget: int
takeOrder
Abe Kebe
client server 31
Message Passing…
message
32
What is Inheritance?
In the real world: We inherit traits from our
mother and father. We also inherit traits from
our grandmother, grandfather, and ancestors.
We might have similar eyes, the same smile,
a different height . . . but we are in many
ways "derived" from our parents.
34
Inheritance…
35
Library Item
Inheritance Catalogue Number Library class
Acquisition date
Cost
Type
hierarchy
Status
Number of copies
Acquire ()
Catalogue ()
Dispose ()
Issue ()
Return ()
Reader Borrower
Affiliation Items on loan
Max. loans
Staff Student
Department Major subject
Department phone Home address
37
Dog Cat
String name String name
String color int age
String getName() String getName()
String getColor() int getAge()
void speak() void speak()
using
inheritance
superclass
Animal
subclass
String name
subclass String getName()
Dog Cat
String color int age
String getColor() int getAge()
38
void speak() void speak()
Advantages of inheritance
• It is an abstraction mechanism which may be
used to classify entities
• It is a reuse mechanism at both the design
and the programming level
• The inheritance graph is a source of
organizational knowledge about domains and
systems during analysis level
39
Polymorphism
• It means the ability to take more than one form.
• To allow an entity such as variable, function or an
object to have more than one form.
Kinds of Polymorphism
- A variable with a given name may be allowed to have
different forms.
- E.g: a variable named EmployeeId can be either Int, or
String.
40
Polymorphism...
41
What is Object-Oriented Analysis and
Design
• OOA: we find and describe objects or
concepts in the problem domain
• OOD: we define how these software objects
collaborate to meet the requirements.
– Attributes and methods.
• OOP: Implementation: we implement the
design objects in, say, Java, C++, C#, etc.
42
OO Analysis and Design
43
Benefits of OOAD
• Reusability: Functions and modules that are written
by a developer can be reused by other developer
without any modification.
44
Benefits of OOAD...
• Reduces complexity of problems: a given
problem can be viewed as a collection of different
objects.
– Each object is responsible for a specific task.
45
Applications of OOAD
46
OOAD and Structured
Object-Oriented (OO) development is very
different from structured development:
47
Comparison
OO: Structured:
Systems decomposed into Systems decomposed into
collections of data objects; functions; functions and data
function + data in one place => modelled separately =>
• System components more • System components are more
independent => more flexible dependent on each other =>
to requirements and requirements and
maintenance changes. maintenance changes more
difficult
•Inheritance and polymorphism • Inheritance and polymorphism
are possible => reuse, not possible => limited reuse
extension, and tailoring of possible.
software/designs is possible. • System components do not
• Closely mirrors how humans map closely to real-world
decompose and solve entities => difficult to manage
48
complex problems. complexity.
Comparison…
OO: Structured:
Process allows for iterative and Process less flexible and largely
incremental development => linear =>
• Integration of programs is • Integration of programs is
series of incremental more complex.
prototypes. • Users or developers provided
• Users and developers get with little or no feedback; see
important feedback system only when it has been
throughout development. completed.
• Testing resources distributed • Testing resources are
more evenly. concentrated in the
• If time is short, coding and implementation stage only.
testing can begin before the • Coding and testing cannot
design is finished. begin until all previous stages
are complete. 49