10.object Oriented Design and UML Diagrams
10.object Oriented Design and UML Diagrams
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
m8 m7
mi are methods
of the object
m1 m6
Data
m2 m5
Object
m3 m4
Model of an 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 :
• Operations supported by an object
• Means for manipulating the data of other
objects
• 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)
6
Object-oriented Concepts
–Multiple Inheritance:
• Subclass can inherit attributes and methods from more than one base
class
7
Object-oriented Concepts
Derived
Faculty Students Staff Faculty Students Staff
Classes
Multiple
Inheritance
8
Object-oriented Concepts
• Key Concepts:
– Abstraction:
• Consider aspects relevant for certain purpose
• Suppress non-relevant aspects
9
Object-oriented Concepts
–Advantages of abstraction:
• Reduces complexity of software
• Increases software productivity
10
Object-oriented Concepts
–Encapsulation:
• Objects communicate outside world through messages
• Objects data encapsulated within its methods
11
Object-oriented Concepts
–Polymorphism:
• Denotes to poly (many) morphism (forms)
• Same message result in different actions by
different objects (static binding)
12
Advantages
of Object-oriented design
13
Advantages
of Object-oriented design
14
Object
modelling using UML
15
Why UML is required?
16
UML diagrams
17
UML diagrams
–Views of a system
• User’s view
• Structural view
• Behavioral view
• Implementation view
• Environmental view
18
UML diagrams
Behavioural View
Structural View - Sequence Diagram
- Class Diagram - Collaboration Diagram
- Object Diagram
- State-chart Diagram
- Activity Diagram
User’s View
-Use Case
Diagram
19
Use Case model
20
Representation of
Use Cases
21
Example of
Use Cases
Play Move
22
Factoring
Use Cases
23
Factoring Using
Generalization
24
Factoring Using
Includes
<<include>> Common
Base use case
use case
<<include>>
<<include>>
<<include>> <<include>>
Paralleling model 25
Factoring Using
Extends
26
Class diagram
27
Class diagram
28
Example of
Class diagram
29
Association Relationship
Library Member
1 borrowed by * Book
30
Aggregation Relationship
31
Aggregation Relationship
1 * 1
Document Paragraph * Line
Representation of aggregation
32
Class Dependency
33
Object diagram
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( );
34
Interaction diagram
35
Interaction diagram
36
Sequence diagram
37
Sequence diagram
information
38
Example of
Sequence diagram
:Library
:Library
:Library Book :Library
Book :Book
Boundary Renewal Member
Register
Controller
confirm
confirm
updateMemberBorrowing
40
Example of
Collaboration diagram
6: * find
:Library
Book :Book
[reserved] Register
9: update
8: apology 5: book 10: confirm
Selected
1: renewBook :Library [reserved]
:Library Book 7: apology
Boundary 3: display Renewal
Borrowing Controller
4: selectBooks
2: findMemberBorrowing
12: confirm
:Library
Member
updateMemberBorrowing
42
Activity diagram
43
Activity diagram
44
Example of
Activity diagram
Academic Section Accounts Section Hostel Office Hospital Department
check
student
records
receive
fees
allot create
hostel hospital
record
register
receive
in
fees
course
conduct
allot medical
room examination
issue
identity card
Activity diagram for student admission procedure at IIT
45
State Chart diagram
46
State Chart diagram
47
Example of
State Chart diagram
order received
Unprocessed
Order
[reject] checked [accept] checked
Rejected Accepted
Order Order
[some items available]
[some items not processed / deliver
available] processed
[all items
Pending available] Fulfilled
Order newsupply Order
49
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.
50
Example 1: Use Case Model
Play Move
51
Example 1: Sequence Diagram
:playMove :playMove
:board
Boundary Controller
acceptMove checkMoveValidity
move
[invalidMove] [invalidMove]
announceInvalidMove
announceInvalidMove
checkWinner
[game over]
[game over] announceResult
announceResult
playMove
checkWinner
displayBoardPositions getBoardPositions
Board PlayMoveBoundary
int position[9]
Controller
announceInvalidMove
announceResult
53
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.
54
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.
55
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.
56
Example 2: Use Case Model
register
Customer customer Clerk
register
sales
Sales Clerk
select
winners
Supermarket
Prize scheme
Manager
57
Example 2: Sequence Diagram for the Select
Winners Use Case
Select
SelectWinners
Winners
SelectWinners
*computeSales
*browse
register
register
checkDuplicate
*match
[duplicate]
showError
generateCIN
create
register :Customer
Record
displayCIN
:Register
:Sales
Sales
History
Boundary
registerSales
RegisterSales
create :Sales
Record
confirm
60
Example 1: Class Diagram
SalesHistory CustomerRegister
selectWinners findWinnerDetails
registerSales register
1 1
* *
SalesRecords CustomerRecord
salesDetails name
address
computerSales browse
browse checkDuplicate
create create
61
Summary
62
Summary
63
Summary
64