11 OOAD Overview

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Object Oriented Analysis &

Design (OOAD) Overview


Lecture 11
Based on slides from Ian Sommerville, University of Lancaster, United
Kingdom, University of St Andrews, Scotland
And on slides Aries Muslim’s site (based on slides from Kasseler?)
Object-Oriented Development
• Object-oriented analysis, design and programming
are related but distinct
• OOA is concerned with developing an object model of
the application domain
• OOD is concerned with developing an object-oriented
system model to implement requirements
• OOP is concerned with realising an OOD using an OO
programming language such as Java or C++

2
©Ian Sommerville 2000
OOAD
• 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
Advantages of OOD
• Easier maintenance. Objects may be
understood as stand-alone entities
• Objects are appropriate reusable components
• For some systems, there may be an obvious
mapping from real world entities to system
objects

4
©Ian Sommerville 2000
OO Design vs. OO Programming
• Object-Oriented Design
• a method for decomposing software architectures
• based on the objects every system or subsystem manipulates
• relatively independent of the programming language used

• Object-Oriented Programming
• construction of software systems as
• Structured collection of Abstract Data Types (ADT)
• Inheritance
• Polymorphism
• concerned with programming languages and implementation issues

5
Objects and object classes
• Objects are entities in a software system that represent instances of
real-world and system entities
• Object classes are templates for objects. They may be used to create
objects
• Object classes may inherit attributes and services from other object
classes

6
©Ian Sommerville 2000
Objects
• Object is an abstraction of something in a problem domain, reflecting
the capabilities of the system to keep information about it, interact
with it, or both.
• Objects are entities in a software system that represent instances of
real-world and system entities

7
Objects
Object Identity Behaviors State

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


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

8
Object Class
• Class is a description of a set of objects that share the same
attributes, operations, methods, relationship and semantics.
• Object classes are templates for objects. They may be used to create
objects.
• An object represents a particular instance of a class.

9
Term of objects
• Attributes: data items that define object.
• Operations: functions in a class that combine to form the behavior of
class.
• Methods: the actual implementation of a procedure (the body of
code that is executed in response to a request from other objects in
the system).

10
The Unified Modeling Language

• Several different notations for describing object-oriented designs


were proposed in the 1980s and 1990s
• The Unified Modeling Language is an integration of these notations
• It describes notations for a number of different models that may be
produced during OO analysis and design
• It is now a de facto standard for OO modelling

11
©Ian Sommerville 2000
Employee object & class
Class Object
Employee Employee16
name: string name: John
address: string address: M Street No.23
dateOfBirth: Date dateOfBirth: 02/10/65
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 () Eployee16.retire(03/08/2005)
retire ()
changeDetails () Eployee16.changeDetail(“X
Street No. 12”) 12
Encapsulation and Data Hiding
• Packaging related data and operations together is called
encapsulation.
• Data hiding: hides the internal data from external by methods
(interface).
• Important in most design paradigms (not just OOAD)

13
Encapsulation
When classes are defined, programmers can specify that certain
methods or state variables remain hidden inside the class.
Visible Methods
u These variables and methods are accessible from within the
Hidden
class, but not accessible outside it. State
u The combination of collecting all the attributes of an object Variables
and
into a single class definition, combined with the ability to hide Methods
some definitions and type information within the class, is
known as encapsulation. Visible Variables

Class
Definition
14
Graphical Model of an Object
Instance balance()
variables

withdraw() theBalance deposit()


acctNumber

Methods
accountNumber()

State variables make up the nucleus of the object.


Methods surround and hide (encapsulate) the state
variables from the rest of the program.

15
Encapsulation
l private attributes and methods are encapsulated within the
class, they cannot be seen by clients of the class
l 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
16
Object communication
• Conceptually, objects communicate by message passing.
• Messages
• The name of the service requested by the calling object.
• Copies of the information required to execute the service
and the name of a holder for the result of the service.
• In practice, messages are often implemented
by procedure calls
• Name = procedure name.
• Information = parameter list.

17
©Ian Sommerville 2000
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

18
Message Passing
message

name = “Alex” name = “Lawrence”


takeOrder(“sofa”, name,
address = employeeNo =15
address, “120799”)
“1 Robinson Rd” commission = 200
budget = 2000
199
placeOrder( ): void takeOrder( ): int
return value
alex lawrence
message

lawrence.takeOrder(“sofa”, “1 Robinson Rd”, “120799”)

object reference method name parameters

19
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
alex lawrence

client server
20
Generalisation and inheritance
• Objects are members of classes that define attribute types and
operations
• Classes may be arranged in a class hierarchy where one class (a super-
class) is a generalisation of one or more other classes (sub-classes)
• A sub-class inherits the attributes and operations from its super class
and may add new methods or attributes of its own
• Generalisation in UML is implemented as inheritance in OO
programming languages

21
©Ian Sommerville 2000
A generalisation hierarchy
Employee

Ma nager Programmer

budgetsControlled project
progLanguage
dateAppointed

Project De pt. Strategic


Ma nag er Ma nager Ma nag er
projects dept responsibilities

22
Library Item
Catalogue Number Library class
Acquisition date
Cost hierarchy
Type
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
23
Libr ary user User class hierarchy
Name
Address
Phone
Registration #
Register ()
De-r egister ()

Reader Borrower
Affiliation Items on loan
Max. loans

Staff Student
Department Major subject
Department phone Home address

24
Multiple inheritance
• Rather than inheriting the attributes and services from a single parent
class, a system which supports multiple inheritance allows object
classes to inherit from several super-classes
• Can lead to semantic conflicts where attributes/services with the
same name in different super-classes have different semantics
• Makes class hierarchy reorganisation more complex

25
Multiple inheritance
Book Voice recording
Author Speaker
Edition Duration
Publication date Recording date
ISBN

Talking book
# Tapes

26
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 organisational
knowledge about domains and systems

27
Problems with inheritance
• Object classes are not self-contained. They cannot be
understood without reference to their super-classes
• Designers have a tendency to reuse the inheritance graph
created during analysis. Can lead to significant inefficiency
• The inheritance graphs of analysis, design and
implementation have different functions and should be
separately maintained

28
Inheritance and OOD
• There are differing views as to whether inheritance is
fundamental to OOD.
• View 1. Identifying the inheritance hierarchy or network is a
fundamental part of object-oriented design. Obviously this can only
be implemented using an OOPL.
• View 2. Inheritance is a useful implementation concept that allows
reuse of attribute and operation definitions. Identifying an
inheritance hierarchy at the design stage places unnecessary
restrictions on the implementation
• Inheritance introduces complexity and this is undesirable,
especially in critical systems

29
Objects Association

• Modeling an association between two classes


means that there is some sort of relationship
between objects of each class that may be
connected.

studies
Student Course
0..* 1..*

30
An association model

Employee
is-member-of Department

is-managed-by

manages
Manager

31
©Ian Sommerville 2000
Object aggregation
• Aggregation model shows how classes that are collections are
composed of other classes

• Similar to the part-of relationship in semantic data models

32
Object aggregation
Study pack

Course title
Number
Year
Instructor

1 1 1 1

1 ..* 1 ..* 1 ..* 0 ..*

Assignment OHP slides Lectur e Videotape


notes
Credits Slides Tape ids.
Text

1 1

1 ..* 1 ..*
Exercises Solutions
#Problems Text
Description Diagrams

33
Object Cohesion & Coupling
• Cohesion describes the relationships within modules.
• Cohesion of a component is a measure of how well it fits together. Each
operation provides functionality that allows the attributes of the object to be
modified, inspected or used as a basis for service provision.
• Coupling describes the relationships between modules
• Coupling is an indication of the strength of interconnections between
program units. Highly coupled systems have strong interconnections, with
program units dependent on each other (shared variables, interchange
control function). Loosely coupled system have program units that are
independent.

34
Polymorphism

• the ability of different objects to perform the


appropriate method in response to the same
message is known as polymorphism.
• the selection of the appropriate method depends
on the class used to create the object

name
Shape getName( )
calculateArea( )

radius side
Circle Square
calculateArea( ) calculateArea( )

35
Example Polymorphism
class Shape {
private String name;
public Shape(String aName) { name=aName; }
public String getName( ) { return name; }
public float calculateArea( ) { return 0.0f; }
} // End Shape class
a generic action
inheritance
class Circle extends Shape {
private float radius;
public Circle(String aName) { super(aName); radius = 1.0f; }
public Circle(String aName, float radius) {
super(aName); this.radius = radius;
} overloading
public float calculateArea() { return (float)3.14f*radius*radius; }
} // End Circle class
overriding

36
class Square extends Shape {
private float side;
public Square(String aName) {
super(aName);
side = 1.0f;
}
public Square(String aName, float side) {
super(aName);
this.side = side;
}
public float calculateArea() {
return (float) side*side;
}
} // End Square class

37
Polymorphism Example
public class ShapeDemoClient {
public static void main(String argv[ ]) {
Shape c1 = new Circle("Circle C1");
Shape c2 = new Circle("Circle C2", 3.0f);
Shape s1 = new Square("Square S1");
Shape s2 = new Square("Square S2", 3.0f); rule of subtype
Shape shapeArray[ ] = {c1, s1, c2, s2};
for (int i = 0; i < shapeArray.length; i++) {
System.out.println("The area of " + shapeArray[i].getName( )
+ " is " + shapeArray[i].calculateArea( )
+ " sq. cm.");
} dynamic binding
} // End main
} // End ShapeDemoClient1 class

38
OO Analysis and Design
OO Analysis - examines requirements from the perspective of the classes and
objects found in the vocabulary of the problem domain. In other words, the
world (of the system) is modelled in terms of objects and classes.

OO Design - OO decomposition and a notation for depicting models of the system


under development. Structures are developed whereby sets of objects
collaborate to provide the behaviours that satisfy the requirements of the
problem.

39
Continuous cycles Sequential/linear stages
Small, high-functioning, collaborative teams Upfront planning and in-depth documentation
Flexible/continuous evolution Works best with well-defined deliverables
Customer involvement Close project manager involvement
40

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy