You are on page 1of 49

CHAPTER - 2

Object Oriented System


Analysis & Design (OOAD)
Generalities and principles

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.

• Functions (behaviour) and data (state)


relating to a single object are self-contained
or encapsulated in one place.

3
Object Oriented Programming
• Programming using objects
• An object represents an entity
– Real world object: car, watch, …
– Abstract object: network connection, …

• Objects have two parts:


– State: Properties of an object.
– Behavior: Things the object can do.
4
Basic Principles of Object Orientation

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

• Software Objects are often used to model real-


world objects.
object state behavior
dog breed, isHungry eat, bark
grade book grades mean, median
light on/off switch 6
Objects…
• Car Example:
– State: Color, engine size, automatic
– Behavior: Brake, accelerate, shift gear

• Person Example:
– State: Height, weight, gender, age
– Behavior: Eat, sleep, exercise, study

7
Objects (more)
Object Identity Behaviors State

An employee “Mr. Abe” Join(), Joined,


Retire() Retired.
A book “Book with title Add(), Rent,
Object Oriented Delete() available,
Analysis Design” reserved
A sale “Sale no 0015, SendInvoiced() Invoiced,
15/12/07” , cancelled.
Cancel().

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:

Class and Object Names


9
Class
• Definition: A class is a blueprint that defines the
states and the behaviors common to all
objects of a certain kind.

• In the real world, you often have many objects of


the same kind.
• For example, a guard dog, snoop dog . . .
• Class is a user defined data type.

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)

Class Name Professor


name
Attributes empID
Operations create( )
save( )
delete( )
change( )

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 Selam Professor Meron

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

Operation: function in a class that


combine to form behavior of class.

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; }

void setName(String n) { name = n; }

int getAge() { return age; }

void setAge(int a) { age = a; }

boolean smellsGood(){return true;}


}
17
Constructing Person Objects
• To create an instance of the Person class with a
name of "kebede" and an age of 22

Person kebede = new Person();


kebede.setName("kebede");
kebede.setAge(22);

• Can we create a Person that has the name


Kebede and the age 22 from the moment it
is created? Home work
• Answer: Yes! 18
BankAccount Example
public class BankAccount {
double balance;
String name;
BankAccount(String n,
double openBalance){
name = n;
balance = openBalance;
} // Continued next slide

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

Source File <<EXE>> <<DLL>>


Name Executable Component
Name Name
Component
Interface
21
What is a Package?
• A package is a general purpose mechanism for organizing similar
elements into groups

• 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

– Example Math class. (contains math classes such as cos() )


22
What is Abstraction?

• Abstraction refers to the act of representing


essential features without including the
background details.
• The abstraction concept is usually used during
analysis:
– i.e deciding only with application domain, not making
design and implementation decision.
• Two popular abstraction:
– Procedure abstraction
– Data abstraction

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!

Shouldn’t ask Service provider


Client

How does an object encapsulate?


What does it encapsulate?
Improves flexibility
26
Encapsulation and Data Hiding
• It refers to the process of combining data and
methods into a single unit called class.
– By this method one cannot access data directly.

• Data is accessible only thru the methods present


inside the class.
• Packaging related data and operations together is
called encapsulation.
• Data hiding: hides the internal data from external by
methods (interface).

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

public methods + printNumCustomer( ): void


+ placeOrder( ): void

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

+ printNumCustomer( ): void + takeOrder( ): void


+ placeOrder( ): void

takeOrder
Abe Kebe

client server 31
Message Passing…
message

name = “Abe” name = “Kebe”


takeOrder(“sofa”, name,
address = employeeNo =15
address, “120799”)
“Mekelle” commission = 200
budget = 2000
199
placeOrder( ): void takeOrder( ): int
return value
Abe Kebe
message

Kebe.takeOrder(“sofa”, “Mekelle”, “120799”)

object reference method name parameters

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.

 In software: Object inheritance is more well


defined! Objects that are derived from other
object "resemble" their parents by inheriting
both state (fields) and behavior (methods).
33
Inheritance...
• It is the process of deriving new classes from
existing classes.
• The derived classes contain:
– all attributes and functions of existing classes plus
– its own attributes and functions.

• Existing class is called as Base class or Super


class and inherited class is called as Derived
class or Sub class.

34
Inheritance…

• Object classes may inherit attributes and


services from other object classes.

• Inheritance represents the generalization/


specialization of a class
(what we have discussed previously).

35
Library Item
Inheritance Catalogue Number Library class
Acquisition date
Cost
Type
hierarchy
Status
Number of copies
Acquire ()
Catalogue ()
Dispose ()
Issue ()
Return ()

Published item Recorded item


Title Title
Publisher Medium

Book Magazine Film Computer


program
Author Year Director
Edition Issue Date of release Version
Publication date Distrib Platform
ISBN
36
Libr ary user User class hierarchy
Name
Inheritance Address
Phone
Registration #
Register ()
De-r egister ()

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...

- A named function can also vary depending


on the parameters it is given.
- The number and name of parameters may
differ.
- Function name is the same.
• Example:
area(int height,int width) for rectangle
and
area(double width) for square.

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

 Unlike functional decomposition, OO views a


complex problem as a meaningful collection
of objects that collaborate to achieve some
higher level behaviour

 using OO should make the job of developing


large, complex systems more manageable.

43
Benefits of OOAD
• Reusability: Functions and modules that are written
by a developer can be reused by other developer
without any modification.

• Inheritance: Thru this we can eliminate redundant


code and extend the use of the existing classes.

• Data hiding: The programmer can hide the data and


functions in a class from other classes.
– It helps the programmer to build secured programs.

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.

• Easy to maintain and upgrade: new objects can


be created with small differences to the existing
ones.
• Message passing: the techniques of message
communication b/n objects makes the interface with
the external system easier.

45
Applications of OOAD

• Application dev’t for smart phones


• Simulation and modelling
• Object-Oriented database
• Computer games and computer animation
• Artificial Intelligence and neural network
• Distributed database
• ...

46
OOAD and Structured
Object-Oriented (OO) development is very
different from structured development:

• Structured approach focuses on major


functions within a system and on the data
used by the functions.

• OO approach focuses on the objects in a


system and on the relationships between
those objects.

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

You might also like