10.object Oriented Design and UML Diagrams
10.object Oriented Design and UML Diagrams
1
Functional oriented software design
2
Object oriented design approach
3
• Similar features objects are kept inside a class
4
Object-oriented Concepts
Basic Mechanisms:
– Objects: All the entities involved in the design are known
as objects
• A real-world entity.
m8 m7
mi are methods
of the object
m1 m6
Data
m2 m5
Object
m3 m4
Model of an object
6
Object-oriented Concepts
Class:
Class defines all the attributes + methods to
perform.
• Instances are objects
• Template for object creation
• Examples: set of all employees, different types of book
7
Object-oriented Concepts
Inheritance:
One class inherits the attributes and methods from another class.
• Allows to define a new class (derived class) by extending or modifying
existing class (base class)
9
Object-oriented Concepts
–Multiple Inheritance:
• Subclass can inherit attributes and methods from more than one base
class
10
Object-oriented Concepts
Derived
Faculty Students Staff Faculty Students Staff
Classes
Multiple
Inheritance
11
Object-oriented Concepts
Abstraction:
Used for handling complexity. It removes irrelevant data and shows
only essential data.
Note :(We have so many features in a system so rather than showing all the features, we only make
visible important features and remove the irrelevant data.)
12
Cont…
Advantages of abstraction:
• Reduces complexity of software
• Increases software productivity
13
Object-oriented Concepts
Encapsulation:
It is the concept of information hiding.
e.g. Mobile app: (we never shows to the user about the
programming used for the application development)
14
Object-oriented Concepts
16
Object-oriented Concepts
–Dynamic binding:
• In inheritance hierarchy, an object can be assigned to another object of its
ancestor class
17
Object-oriented Concepts
–Dynamic binding:
• Exact method cannot be known at compile time
18
Object-oriented Concepts
– Composite objects:
• Object containing other objects
19
Advantages
of Object-oriented design
20
Advantages
of Object-oriented design
21
Object
modelling using UML
22
UML Diagram
23
Structure Diagram: (static aspects)
• Focuses on static aspects of a system. (including its component
and their relationships).
e.g. CAR
- component (engine, wheel, seat etc.)
25
26
Why UML is required?
27
UML diagrams
28
UML diagrams
Views of a system
• Structural view
• Behavioral view
• User’s view
• Implementation view
• Environmental view
29
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
30
UML User’s View: Use Case model
33
Use Case diagram: Book my show
34
Example of
Use Cases
Play Move
35
Factoring Use Cases
36
Factoring Using
Generalization
37
38
39
Factoring Using
Includes
<<include>> Common
Base use case
use case
<<include>>
<<include>>
<<include>> <<include>>
Paralleling model 40
Factoring Using
Extends
41
Class diagram: Structure diagram
Class attribute
Class operations
42
Class and ObjecDaigram
43
Class and Object Diagram
44
Class and ObjecDaigram
45
Class diagram
has a
Current
47
Object Diagram
48
Example of Class diagram
issueBook( );
findPendingBooks( ); Compartments for class: name, -attributes & operations
findOverdueBooks( );
returnBook( );
findMembershipDetails( );
49
Different representations of the Library Member class
• These relationships, which we setup between classes.
• Association
• Dependency
• Aggregation
• Composition
• Generalization.
50
Relation: Generalisation
• e.g.
Employee Student
Manager HR PG UG
51
Relation : Association
Library Member
1 borrowed by * Book
Aggregation Composition
(has a relationship)
52
Aggregation Relationship
– It can be transitive
53
cont. ……..Aggregation Relationship
1 * 1
Document Paragraph * Line
Representation of aggregation
e.g.
1 *
WhatsApp Whatsapp group
e.g.
1 *
Bank Branches
Representation of composition
55
56
Class Dependency
57
Class Diagram: LMS
58
Cont.
59
Cont.
60
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( );
61
Interaction Diagram
– Models how groups of objects collaborate to realize some behaviour
62
Sequence Diagram: Behavioural Diagram
– Shows interaction among objects as two-dimensional chart
– Objects request are shown with solid arrow line and responses are
shown with dotted arrow line.
64
Menu
Cont. Sequence diagram: Restaurant System
65
Cont. Sequence diagram: Library System
66
67
Time ordering matters
68
LMS: Collaboration Diagram
69
Behavioural Diagram: Activity diagram
70
Activity diagram: ATM Transaction System
71
Example of Activity diagram for student admission procedure
check
student
records
receive
fees
allot create
hostel hospital
record
register
receive
in
fees
course
conduct
allot medical
room examination
issue
identity card
72
Behavioural Diagram : State Chart diagram
73
Elements of state chart diagram
74
Order Management System: State Diagram
75
Cont. Order Management System
76
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
78
THANKS YOU
79
EXTRA EXAMPLES
80
Example Pattern
• Expert
– Problem: Which class should be responsible for doing certain
things
– Solution: Assign responsibility to the class that has the
information necessary to fulfil the required responsibility
81
Example Pattern
• Creator
– Problem: Which class should be responsible for creating a new
instance of some class?
– Solution: Assign a class C1 the responsibility to create class C2 if
• C1 is an aggregation of objects of type C2
• C1 contains object of type C2
82
Example Pattern
• Controller
– Problem: Who should be responsible for handling the actor
requests?
– Solution: Separate controller object for each use case.
83
Example Pattern
• Facade
– Problem: How should the services be requested from a service
package?
– Context (problem): A package (cohesive set of classes),
example: RDBMS interface package
– Solution: A class (DBfacade) can be created which provides a
common interface to the services of the package
84
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.
85
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.
86
Example 1: Use Case Model
Play Move
87
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
89
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.
90
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.
91
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.
92
Example 2: Use Case Model
register
Customer customer Clerk
register
sales
Sales Clerk
select
winners
Supermarket
Prize scheme
Manager
93
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 :Register
:Sales
Sales Sales
History
Boundary Controller
RegisterSales registerSales
registerSales
create :Sales
Record
confirm
confirm
96
Example 2: Sequence Diagram for the Register
Sales Use Case
:Register
:Sales
Sales
History
Boundary
registerSales
RegisterSales
create :Sales
Record
confirm
97
Example 1: Class Diagram
SalesHistory CustomerRegister
selectWinners findWinnerDetails
registerSales register
1 1
* *
SalesRecords CustomerRecord
salesDetails name
address
computerSales browse
browse checkDuplicate
create create
98
Summary
99
Summary
100
Summary
101