Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
70 views

Object Oriented Design and UML Diagrams

The document discusses key concepts in object-oriented design including objects, classes, inheritance, encapsulation, and polymorphism. It also covers UML modeling and diagrams commonly used for object-oriented analysis and design. Factoring techniques for use cases such as generalization, inclusion, and extension are presented with examples.

Uploaded by

rohan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Object Oriented Design and UML Diagrams

The document discusses key concepts in object-oriented design including objects, classes, inheritance, encapsulation, and polymorphism. It also covers UML modeling and diagrams commonly used for object-oriented analysis and design. Factoring techniques for use cases such as generalization, inclusion, and extension are presented with examples.

Uploaded by

rohan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

Object-Oriented

Software Design (lecture 7)

1
Object-oriented Concepts
● Basic Mechanisms:
● Objects:
● A real-world entity.
● A system is designed as a set of
interacting objects.
● Consists of data (attributes) and
functions (methods) that operate on
data
● Hides organization of internal information
(Data abstraction)
● Examples: an employee, a book etc.

2
Object-oriented Concepts

m m
8 7 mi are
methods
of the object

m m
1 Data 6
m m
2 5
Objec
t

m m
Model3 of an
4
object
3
Object-oriented Concepts
● Class:
● Instances are objects
● Template for object creation
● Examples: set of all employees, different
types of book

4
Object-oriented Concepts
● Methods and message:
● Operations supported by an object
● Means for manipulating the data of
other objects
● Invoked by sending message
● Examples: calculate_salary, issue-
book, member_details, etc.

5
Object-oriented Concepts
● Inheritance:
● Allows to define a new class (derived
class) by extending or modifying existing
class (base class)
● Represents Generalization-
specialization relationship
● Allows redefinition of the existing
methods (method overriding)

6
Object-oriented Concepts
● Multiple Inheritance:
● Subclass can inherit attributes and
methods from more than one base class

● Multiple inheritance is represented by


arrows drawn from the subclass to each
of the base classes

7
Object-oriented Concepts

Base Base
LibraryMember LibraryMember
Class Class

Derived
Faculty Students Staff Faculty Students Staff
Classes Multiple

Inherita
nce
UnderGrad PostGrad Research UnderGrad PostGrad Research

8
Abstraction

● Consider aspects relevant for certain


purpose
● Suppress non-relevant aspects
● Supported at two-levels i.e. class
level where base class is an
abstraction and object level where
object is a data abstraction entity.

9
Object-oriented Concepts
● Encapsulation:
● Objects communicate outside world
through messages
● Objects data encapsulated within its
methods

10
Object-oriented Concepts

m
4
m
3 m
5

m
2
Data
m
6
m
1

Methods

Concept of
encapsulation
11
Object-oriented Concepts
● Polymorphism:
● Denotes to poly (many) morphism
(forms)
● Same message result in different
actions by different objects (static
binding)

12
Object-oriented Concepts
● Composite objects:
● Object containing other objects

13
Advantages
of Object-oriented design
● Code and design reuse
● Increased productivity
● Ease of testing & maintenance
● Better understandability
● Its agreed that increased
productivity is chief advantage

14
Object
modelling using UML
● UML is a modelling language
● Not a system design or
development methodology
● Used to document object-
oriented analysis and design
● Independent of any specific
design methodology

15
Why UML is required?
● Model is required to capture only
important aspects
● UML a graphical modelling tool, easy
to understand and construct
● Helps in managing complexity

16
UML diagrams
● Nine diagrams to capture
different views of a system
● Provide different perspectives of
the software system
● Diagrams can be refined to get
the actual implementation of the
system

17
UML diagrams
● Views of a system
● User’s view
● Structural view
● Behavioral view
● Implementation view
● Environmental view

18
UML diagrams

Behavioural View
Structural - Sequence Diagram
View - Collaboration Diagram
- Class Diagram - State-chart Diagram
- Object Diagram - Activity Diagram
User’s View
- Use Case
Diagram

Implementation Environmental
View View
- Component Diagram - Deployment Diagram

Diagrams and views in


UML
19
Are all views required?

● NO
● Use case model, class diagram and
one of the interaction diagram for a
simple system
● State chart diagram in case of many
state changes
● Deployment diagram in case of large
number of hardware components

20
Use Case model
● Consists of set of “use cases”
● An important analysis and design
artifact
● Other models must confirm to this
model
● Not really an object-oriented model
● Represents a functional or process
model

21
Use Cases
● Different ways in which system can be used
by the users.
● Corresponds to the high-level requirements.
● Represents transaction between the user
and the system.
● Define behavior without revealing internal
structure of system.

22
Use Cases
● Normally, use cases are independent
of each other
● Implicit dependencies may exist
● Example: In Library Automation
System, renew-book & reserve-book
are independent use cases. But in
actual implementation of renew-book,
a check is made to see if any book has
been reserved using reserve-book

23
Example of
Use Cases
● For library information system
● issue-book
● Query-book
● Return-book
● Create-member
● Add-book, etc.

24
Representation of
Use Cases
● Represented by use case diagram
● Use case is represented by ellipse
● System boundary is represented by
rectangle
● Users are represented by stick
person icon (actor)
● Communication relationship
between actor and use case by line
● External system by stereotype

25
Example of
Use Cases

Play
Move

Playe Tic-tac-toe
r game

Use case
model

26
Factoring
Use Cases
● Complex use cases need to be
factored into simpler use cases
● Represent common behavior across
different use cases
● Three ways of factoring
● Generalization
● Includes
● Extends

27
Factoring Using
Generalization

Pay membership
fee

Pay through Pay through library


credit card pay card

Use case
generalization

28
Factoring Using
Includes
Common
Base <<include>
>
use
use case
case
Use case inclusion

Base Base
use case use case

<<include>
> <<include>
>
<<include> <<include>
> >

Base Base Base


use case use case use case

Paralleling 29
model
Factoring Using
Extends

Common
Base <<extends>
>
use
use case
case

Use case extension

30
Class diagram
● Describes static structure of a system
● Main constituents are classes and
their relationships:
● Aggregation
● Association
● Various kinds of dependencies

31
Class diagram
● Entities with common features, i.e.
attributes and operations
● Classes are represented as solid
outline rectangle with compartments
● Compartments for name, attributes
& operations
● Attribute and operation compartment
are optional for reuse purpose

32
Example of
Class diagram

LibraryMember LibraryMember LibraryMember


Member Name Member Name
Membership Number Membership Number
Address Address
Phone Number Phone Number
E-Mail Address E-Mail Address
Membership Admission Membership Admission
Date Date
Membership Expiry Date Membership Expiry Date
Books Issued Books Issued
issueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
findMembershipDetails( );

Different representations of the LibraryMember


class
33
Association Relationship

Library 1 borrowed * Book


Member by

Association between two


classes

34
Aggregation Relationship
● Represent a whole-part relationship
● Represented by diamond symbol at
the composite end
● Cannot be reflexive(i.e. recursive)
● Not symmetric
● It can be transitive

35
Aggregation Relationship

1 * 1
Document Paragraph * Line

Representation of
aggregation

36
Composition Relationship

● Life of item is same as the order

1 *
Order Item

Representation of
composition

37
Class Dependency

Dependent Class Independent Class

Representation of dependence between


class

38
Object diagram

LibraryMember LibraryMember LibraryMember

Mritunjay Mritunjay
B10028 B10028
C-108, Laksmikant Hall C-108, Laksmikant Hall
1119 1119
Mrituj@cse Mrituj@cse
25-02-04 25-02-04
25-03-06 25-03-06
NIL NIL

IssueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
findMembershipDetails( );

Different representations of the LibraryMember


object
39
Interaction diagram
● Models how groups of objects
collaborate to realize some behaviour

● Typically each interaction diagram


realizes behaviour of a single use case

40
Interaction diagram

● Two kinds: Sequence &


Collaboration

● Two diagrams are equivalent but


portrays different perspective

● These diagram play a very important


role in the design process

41
Sequence diagram
● Shows interaction among objects as two-
dimensional chart
● Objects are shown as boxes at top
● Objects existence are shown as
dashed lines (lifeline)
● Objects activeness, shown as
rectangle on lifeline

42
Sequence diagram

● Messages are shown as arrows


● Message labelled with message name
● Message can be labelled with
control information
● Two types of control information:
condition ([]) & an iteration (*)

43
Example of
Sequence diagram
:Library
:Library
:Library Book :Library
Book :Book
Boundary Renewal Member
Register
Controller

renewBoo find
k MemberBorrowing
displayBorrowin
g
selectBook bookSelecte
s d *
[reserved find
]
[reserved apolog
] y updat
apolog e
y
confirm

confir
m updateMemberBorrowin
g
Sequence Diagram for the renew book use
44
case
Collaboration diagram
● Shows both structural and behavioural
aspects
● Objects are collaborator, shown as boxes
● Messages between objects shown as a
solid line
● Message is shown as a labelled arrow
placed near the link
● Messages are prefixed with sequence
numbers to show relative sequencing

45
Example of
Collaboration diagram
6: *
:Library
find
Book :Book
[reserved Register
] 9:
8: 10: confirm update
5: book
apology Selecte
1: renewBook d [reserved
:Library
:Library Book ]
7:
Boundary 3: display Renewal apology
Borrowin Controller
g
4:
selectBooks 2:
findMemberBorrowing
12:
confirm :Library
Member

updateMemberBorrowin
g
Collaboration Diagram for the renew book use
case 46
Example 1: Tic-Tac-Toe
Computer Game
● A human player and the computer make
alternate moves on a 3 3 square.
● A move consists of marking a previously
unmarked square.
● The user inputs a number between 1
and 9 to mark a square
● Whoever is first to place three
consecutive marks along a straight line
(i.e., along a row, column, or diagonal)
on the square wins.
47
Example 1: Tic-Tac-Toe
Computer Game
● As soon as either of the human player or
the computer wins,
● a message announcing the winner should be
displayed.
● If neither player manages to get three
consecutive marks along a straight line,
● and all the squares on the board are filled up,

● then the game is drawn.


● The computer always tries to win a
game.

48
Example 1: Use Case Model

Play
Move

Playe Tic-tac-toe
r game

49
Example 1: Sequence Diagram

:playMove :playMove
:board
Boundary Controller

acceptMov checkMoveValidity
e
mov
[invalidMove [invalidMove
e
] ]
announceInvalidMov
announceInvalidMov
echeckWinne
e
r
[game
[game over]
announceResul
over]
announceResul t
t playMov
e
checkWinne
r
[game [game
over] over]
announceResul
announceResul
t t
displayBoardPosition getBoardPosition
s s
[game not
over]
promptNextMov
e
Sequence Diagram for the play move use
50
case
Example 1: Class Diagram

Boar PlayMoveBoundar
d y
int
position[9]
checkMove Validity announceInvalidMov
checkResult e
playMove announceResult
displayBoard

Controlle
r

announceInvalidMov
e
announceResult

51
Example 2: Supermarket Prize
Scheme
● Supermarket needs to develop
software to encourage regular
customers.
● Customer needs to supply his
residence address, telephone
number, and the driving licence
number.
● Each customer who registers is
assigned a unique customer
number (CN) by the computer.
52
Example 2: Supermarket Prize
Scheme
● A customer can present his CN to
the staff when he makes any
purchase.
● The value of his purchase is
credited against his CN.
● At the end of each year, the
supermarket awards surprise gifts
to ten customers who make
highest purchase.
53
Example 2: Supermarket Prize
Scheme
● Also, it awards a 22 carat gold coin
to every customer whose
purchases exceed Rs. 10,000.
● The entries against the CN are
reset on the last day of every year
after the prize winner’s lists are
generated.

54
Example 2: Use Case Model

register
Custome customer Cler
r k

register
sales

Sales
Clerk select
winners

Supermarket
Prize scheme
Manage
r

55
Example 2: Sequence Diagram for
the Select Winners Use Case
: :
SelectWinn SelectWinn :Sales :Sales :Customer :Customer
er er History Record Register Record
Boundary Controller

Select
SelectWinner
Winner
s SelectWinner
s
s *computeSale
s

*brows
e

[for each
winner]find
announce [for each
WinnerDetails winner]
s brows
e

Sequence Diagram for the select winners use


56
case
Example 2: Sequence Diagram for
the Register Customer Use Case
: :
SelectWinn SelectWinn :Customer :Customer
er er Register Record
Boundary Controller

registe
r registe
r checkDuplicat
e
*matc
h
[duplicate
]
showErro
r
generateCI
N
creat
registe e :Customer
r Record
displayCI
N

Sequence Diagram for the register customer use


57
case
Example 2: Sequence Diagram for
the Register Sales Use Case

:Register :Register
:Sales
Sales Sales
History
Boundary Controller

RegisterSale registerSale
s s registerSale
s
creat :Sales
e Record

confir
confir m
m

Sequence Diagram for the register sales use case

58
Example 2: Sequence Diagram for
the Register Sales Use Case

:Register
:Sales
Sales
History
Boundary

registerSale
RegisterSale s
s
creat :Sales
e Record

confir
m

Refined Sequence Diagram for the register sales use


case

59
Example 1: Class Diagram

SalesHistor CustomerRegiste
y r

selectWinner findWinnerDetail
s s
registerSales register

1 1

* *
SalesRecord CustomerRecor
s d
salesDetail name
s addres
computerSale s
browse
s checkDuplicat
browse e
create create

60
Summary

● We discussed object-oriented
concepts
● Basic mechanisms: Such as objects,
class, methods, inheritance etc.
● Key concepts: Such as abstraction,
encapsulation, polymorphism,
composite objects etc.

61
Summary
● We discussed an important OO language
UML
● Its origin, as a standard, as a model
● Use case representation, its factorisation
such as generalization, includes and extends
● Different diagrams for UML representation
● In class diagram we discussed some
relationships association, aggregation,
composition and inheritance

62
Summary
● Some more diagrams such as
interaction diagrams (sequence and
collaboration), activity diagrams,
state chart diagram
● We discussed OO software
development process and patterns
● In this we discussed some patterns
example and domain modelling

63

You might also like