Chapter6 OODesign
Chapter6 OODesign
Object-orientedconcepts
Unified Modelling Language (UML)
Structure View
Behavioural View
User’s view
Implementation View
Environmental View
OOAD Overview
Object-Oriented Concepts
Object-oriented(OO) design techniques are
extremely popular:
abstraction).
Model of an Object
m8 m7
mi are methods
of the object
m1 m6
Data
m2 m5
Object
m3 m4
Class
Instances are objects
Template for object creation
Considered as abstract data type (ADT)
Examples: Employees, Books, etc.
Sometimes not intended to produce instances:
Abstract classes
Methods and Messages
Operations supported by an object:
Means for manipulating the data of other
objects.
Invoked by sending a message (method
call).
Examples:
calculate_salary, issue-book,
member_details, etc.
Encapsulation
• Objects communicate with outside world
through messages:
― Data of objects encapsulated within its methods.
― Data accessible only through methods.
Encapsulation
m4
m3
m5
m2 Data
m6
m1
Methods
Concept of encapsulation
Polymorphism
OMT
UML
Booch’s
OOSE Methodology
UML as A Standard
Adopted by Object Management Group (OMG
in 1997
OMG is an association of industries
Promotes consensus notations and techniques
Used outside software development
Example car manufacturing
Why are UML Models Required?
No
Use case diagram, class diagram and one of the
interaction diagram for a simple system
State chart diagram required to be developed when a
class state changes
Deployment diagram in case of large number of
hardware components used to develop the system
Object responsibility
Objects have three responsibilities
What they do
◦ Operations / Functions
HealthClubMember
Class attributes
operations
Objects
• Relationships
A RELATIONSHIP is what a class or an object knows
about another class or object.
[Object] Associations
• FacultyInformation - CourseInformation
• StudentInformation – CourseInformation
In this example:
• Removal of a University
Course should also remove
UniversityCourse Students that are in the
Course but not Student
Information.
{
Member
memberNumber
firstName Expanded view of a
lastName
Class into its three
attributes telephone
address sections:
city
etc... Top: Class Name
{
checkOutVideo Middle: attributes
operations checkInVideo Bottom: operations
buyItem
etc...
Class Diagram Relationship
Class
◦ Generalization
Object
◦ Association
◦ Aggregation
◦ Composition
UML Class Diagram notation
Class
Generalization
Relationship
Object Object
Aggregation Composition
Object Association Association Association
n n 1..* 1
0..* 0..*
Multiple inheritance is allowed in the UML but can complicate the class
model’s understanding and implementation (e.g., C++ supports but Java
and Smalltalk do not).
Generalization Example
<<abstract>>
Role
attributes
operations
Person
attributes
operations
Supertype
discriminator
Subtype 1 Subtype 2
Generalization – Multiple Classification
Discriminator
Doctor
role
<<abstract>>
Nurse
Person
patient
Lab Attend
Patient
#2
#1
Associations
A semantic relationship between two or more classes
that specifies connections among their instances.
A structural relationship, specifying that objects of one
class are connected to objects of a second class.
An association between two classes indicates that
objects at one end of an association “recognize”
objects at the other end and may send messages to
them.
Multiplicity
◦ The number of instances of the class, next to which
the multiplicity expression appears, that are
referenced by a single instance of the class that is at
the other end of the association path.
◦ Indicates whether or not an association is mandatory.
◦ Provides a lower and upper bound on the number of
instances.
Multiplicity Indicator
Exactly one 1
2..* Door
1..*
Car House
Whole Part
Test for Aggregation
◦ Is the phrase “has - a” fit in the relationship
A car “has a “ door.
1 *
Order Item
Aggregation vs. Composition
Composition:
◦ Composite and components have the same
life.
Aggregation:
◦ Lifelines are different.
Consider an order object:
◦ Aggregation: If order items can be changed
or deleted after placing the order.
◦ Composition: Otherwise.
Case Study - Asignment
The police department has many people working under
various wings. A traffic police is also an employee of the
police department. A system needs to be developed for
recording the details of the violations. If a traffic police
catches an offender he has to file a report with the date of
occurrence of violation.
TrafficReport Offender
TrafficPoliceman 1 issues * id : long 1..* 1 name : String
description : String id : long
occuredAt : Date
reports of
1..*
Policeman
id : long Violation
name : String id : long
rank : int description : String
<<abstract>>
Use Case Diagram
User’s view of the system
Play Move
Player
BCA MCA
registration registration
Includes
Use cases that are included as parts of other use
cases. Enable to factor common behavior.
The base use case explicitly incorporates the
behavior of another use case at a location specified in
the base.
The included use case never stands alone. It only
occurs as a part of some larger base that includes it.
Enables to avoid describing the same flow of events
several times by putting the common behavior in a
use case of its own
Includes - Example
Issue Hall
Ticket <<include>>
verifying
student id
View SE <<include>>
Marks
Extends
Use cases that extend the behavior of other
core use cases.
Accounts
Print
Query balance
Balance sheet
Receive Make
grant payments
Example – Use Case
place
place <<extend>> conference
phone call
call
cellular
network receive
phone call
user
Interaction Diagram
process
lifetime
Object validate
activeness if ( payment ok )
if ( not in stock )
deliver
back order
get address
mail to address
message
Example - Sequence Diagram
:Library
:Library
:Library Book :Library
Book :Book
Boundary Renewal Member
Register
Controller
confirm
confirm
updateMemberBorrowing
register
Customer customer
register
sales
Sales Clerk
select
winners
Supermarket
Prize scheme
Manager
XYZ Bazaar – Sequence Diagram
Step 1 – Identify the various sequences from
the user case diagram
◦ Registration of customer
◦ Registration of sales
◦ Selection of Prize winners
Contd..
Customer Record
Registration of customer
Customer Info
Sales Record
Sales Info Registration of sales
* *
Sales Records Customer Record
Contd..
Boundary and Controller Classes
◦ RegisterCustomerBoundary
◦ RegisterCustomerController
◦ RegisterSalesBoundary
◦ RegisterSalesController
◦ SelectWinnerBoundary
◦ SelectWinnerController
Sequence Diagram – Register Customer
register
register
checkDuplicate
*match
[duplicate]
showError
generateCIN
create
register :Customer
Record
displayCIN
Sequence diagram – Register Sales
:Register :Register
:Sales
Sales Sales
Info
Boundary Controller
RegisterSales registerSales
registerSales
create :Sales
Record
confirm
confirm
Sequence diagram – Select Winner
SelectWinners
SelectWinners
*computeSales
*browse