Tek Sap 08 Ooaduml Showfiles
Tek Sap 08 Ooaduml Showfiles
Tek Sap 08 Ooaduml Showfiles
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 1
Objective
To understand the Object Oriented way of approaching a
problem and to understand the modelling of Object
orientation using UML
To gain a good knowledge of using UML for designing
projects following Object Oriented Approach
To use Magic Draw tool to draw diagrams of UML
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 2
Agenda
(00:20) Introduction to modelling
(00:15) Break
(00:15) Break
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 4
Resolution for complexity
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 5
Two Methods of Decomposition
Algorithmic Decomposition
Programs={Data Structures}+{Operations}
Object-Oriented Decomposition
Object={Data Structures}+{Operations}
Programs=Objects
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 6
Algorithmic Decomposition / Functional
Decomposition
ReserveTicket()
cancel reservation()
AddtrainDetails()
View_waitingList() e.t.c
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 8
Object-Oriented Decomposition
Decomposing a system into objects, the basic
components of the design
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 9
Example of Algorithmic Decomposition
Passenger
Train
Ticket e.t.c
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 10
Advantages of Object-Oriented Decomposition
Better understanding of the system.
Easy to Maintain.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 11
Where OO can be used?
Rapidly changing
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 12
Object - Definition
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 13
Object - State
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 14
Object - Behaviour
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 15
Object - Identity
“is the river the same river every day, even though the same
water never flows through it??”
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 16
What is your view about class and object?
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 17
Object-Doughnut notation
Methods
Data
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 18
Elements of Object Model - Class
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 19
Class & Objects
objects Object
References
redRose
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 20
Difference between Class and Object
Class Object
Class is a type/template for Object is an instance of the
similar objects class, with each instance
behaving identically
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 21
Implementations – Java Syntax for Class
class classname
{
//member variables
datatype membername;
//methods
returntype methodname()
{
:
}
}
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 23
Implementations – Java Syntax for Object
Define Relationships
- create Hierarchies
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 25
Object Oriented Analysis
Identify Sub-systems
Grouping of logically similar systems.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 26
CRC – Class-Responsibility-Collaboration cards
Introduced by
Ward Cunningham & Kent Beck,
Tektronix Research Lab.
Class Name
Responsibility Collaboration
Extract responsibilities With whom does this class 4”
from requirements need to collaborate to
specification by fulfil its responsibilities?
looking at verbs Who needs to make use of
& Information the responsibilities
defined
for this class?
6”
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 27
CRC – A Sample
Grade
3 ..
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 28
How to identify classes?
Look for…
Tangible things
Roles
Events
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 29
Class
Candidate Class
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 30
What are the Principles of the Object Oriented
Model?
Major Themes
(mandatory elements for any OOM):
Abstraction
Encapsulation
Modularity
Hierarchy
Polymorphism
Minor Themes
(useful but not essential part of OOM)
Typing
Persistence
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 31
Abstraction
Definition:
Example:
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 32
Encapsulation
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 33
Implementation of Encapsulation
Access specifiers
Public
Private
Protected
Default
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 34
Implementation of Encapsulation
class Book
{
private int id;
private string name;
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 35
Modularity
Abstractions classes
A module package
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 36
Hierarchy
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 37
Inheritance
Name
Person age
Employee Id
Salary
Department
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 38
Inheritance
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 39
Implementation of Inheritance
class Person
{
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 40
Types Inheritance
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 41
Aggregation
Example: Car
Engine (is a part of a car)
Computer
Keyboard (is a part of computer)
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 42
Polymorphism
Son / Daughter
Employee
Husband / Wife
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 43
Implementation of Polymorphism
Compile Time
Method Overloading (Ad-hoc Polymorphism)
Example: void swap(int, int)
void swap(char, char)
void swap(float, float)
Can I Have?
cannot be overloaded based on
void swap(int,int) return type
int swap(int, int)
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 44
Polymorphism
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 46
Minor Themes - Persistence
Persistence:
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 47
Minor Themes - Typing
Typing:
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 48
Minor Themes - Typing
Static or early binding means that the types of all variables and
Expressions are fixed at the time of compilation.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 49
Object Oriented Analysis and
Design
As the name suggests it is one of the approaches to solve a problem
where modelling is done on the basis of real world objects.
Definition:
A model is a simplification (or) representation of reality.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 50
Model – Why? and Aims
But why?
We build models so that we can understand the system
We are building, better.
Model complex systems to narrow down the problem view.
To comprehend a systems in its entirety.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 51
OOAD and UML
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 52
Modelling Language
A modelling Language is one which is used to analyse the
system better.(not a programming language as it is used to
Solve the problem).
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 54
Building blocks of UML
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 55
Architecture and the UML
Conceptual Physical
Package, subsystem Interaction
State machine
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 56
A Road Map . . .
Activity
Deployment
UML Diagrams
Not Part Of UML
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 57
Use Case Diagram
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 58
Use-Case Diagrams
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 59
Use case Diagram – Actor
Definition:
An actor is someone or something outside the system that
interacts with the system.
Usecase Notation
Name of the usecase
Usecase- A Sample
Add Student Details
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 61
Supermarket Example
Process Order
Sales Person
Place Order
<<inclu
Track Order de>>
Validate User
lude>>
c
<<in
Place Order
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 63
Use case Diagram – Relation - Extend
Extension point
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 64
Use case Diagram – Relation - Generalization
Generalization
Use cases can inherit from other use Academic Clerk
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 65
Use case Diagram – SMPS
c lu de>>
<<in
Registration Officer
System Boundary
Academic Supervisor
<<extend>>
Academic Clerk
SMPS
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 66
Textual Use case [Use case Specification]
A scenario: The customer browses the catalogue and adds desired items to
the shopping cart. When he wishes to pay, he describes the shipping and card
information and confirms sale. The system checks the authorization on the
credit card and confirms the sale both immediately and with a follow-up email..
Buy a Product
Actor: Customer
1 Customer browses the catalogue and selects items to buy.
2 Customer fills in shipping information.
3 System presents full information, including shipping.
4 Customer fills in credit card information.
5 System authorizes purchase.
6 System confirms sale immediately
7 System sends conformation email.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 68
Textual Use case – A Sample
Alternative: Authorization failure
At step 5,system fails to authorize credit purchase
Allow customer to re-enter credit card information.
Go to step4
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 70
Class - Elided
A class is a the framework for set of objects, which share
the same attributes, operations, relationships and semantics.
Also known as classifier.
Notation:
Every class has a name. A name can be simple, where in
only the name of the class is specified.
Class Name
Elided class notation
Samples
Student
smps::Student
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 71
Class - compartmentalized
deleteStudent()
InvalidSIDException
Exceptions
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 72
Class - Attributes
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 73
Class - Attributes
changeable – by default
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 74
Class – Operations
Property string :
isQuery – operation does not have any side effects.
Parameter list can have
[direction] name : type [=default value] or [data type] name:type
Employee
+ setEmployee( e : Employee)
+ getEmployee():Employee {isQuery}
+ initializeID(in IDNo :integer=100)
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 75
Responsibilities
Employee
Employee
<<basic details>>
- empId : Integer
- empName : String
- dateOfBirth : Date
<<employee details>>
- salary : double = 1000.00
- deptName : String
<<Getter>>
+ getEmpId() : Integer
<<Setter>>
+ setEmpId(id : Integer)
Responsibilities
- maintain employee details
- determine employee age
- setting employee details
Exceptions thrown
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 77
Relationships
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 78
Association
We can also show how many objects may be connected for an instance
of an association relationship. This is called as multiplicity.
It defines how many objects participate in relationships.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 79
Multiplicity
Exactly one - 1
Zero or one - 0..1
Many - 0..* or *
One or more - 1..*
Exact Number - e.g. 3..4 or 6
Or a complex relationship - e.g. 0..1, 3..4, 6..* would
mean any number of objects other than 2 or 5
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 80
Multiplicity – Examples
1 has
1..*
school department
teaches
1..* 1..3
instructor subject
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 81
Association Class
we can also show an association class in an association
relationship. An association class is one that makes it
possible for the association to exist between two other
classes.
Transaction
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 82
Inheritance or Generalization
Examples:
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 83
Inheritance or Generalization – Example
Operating System
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 84
Aggregation
The class at one end of the relationship will contain classes at the other
end of the relationship. It is also called a whole part relationship.
Signifies the “part of” or “has a” relationship.
Examples:
FourWheeledVehicle
4 2..5
Door Seat
It doesn’t link the life time of the whole and its parts. An aggregation
is shown by a diamond next to the class representing the whole
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 86
Composition – a special form
1
Building Roof
Point
Polygon
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 87
Dependency
Payroll
Employee
Generator
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 88
Realization
Interface :
An interface is formally equal an abstract class with no
attributes and methods(implementations ), only abstract
Operations.
(or) <<interface>>
Interface Name
Interface Name
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 89
Realization
ICICIBank <<interface>>
Bank
ICICIBank
Bank
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 90
Class Diagram
Class
Interfaces
Relationships between them
Notes and Constraints.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 91
Adornments
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 92
Notes
9
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 93
Tagged Values
Example:
{version=1.3}
{author=Steve}
{date=27/11/2007}
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 94
Constraint
Example:
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 95
Stereotypes
Example:
<<extend>>
<<include>>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 96
The real world scenario
Objects in real world are not static. There are very dynamic and they
communicate by messages.
In software, so far we have one view of system design, i.e., static or structural
view. It is impossible to capture all details of a complex system through just
one view.The structural modelling of UML is largely static.
We depict the abstractions and the objects that are created out of these
abstractions, in the structural model. UML provides dynamic modelling of
elements.Dynamic modelling is also refereed as behavioural modelling.
Elements:
Objects
Messages
Lifeline
Activation Box (or) Focus of Control
Notes and Constraints(Like all other diagrams)
Actor
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 99
Lifeline &Activation Box (or)Focus of Control
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 100
Messages
A message is one that goes from one object to another, goes from
one object’s life line to other object’s lifeline.
Notation
or
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 101
Messages
Notation
Notation
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 103
<<create>>
Preferred
:A
<<create>>
:B
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 104
<<destroy>>
:A :B
<<destroy>>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 105
The Full Picture
X-Axis (objects)
object:
:AnotherClass :AClass
SomeClass
AnotherMethod() Object
Life Line
Y-Axis (time)
method
aMethod()
Activation
YetAnotherMethod box
Self call
return
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 106
Example
User Name
fetchUser : User
Password
validateUser
compareUser
Submit :boolean
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 107
Example
:LoginUI :LoginController
Customer
Username,pwd validateUser(u,p)
<<create>>
:User
fetctUser(u)
compareUser
(u,p,User)
User-status
User-status <<destroy>>
X
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 108
Try this out…..
Pin Number
verifyPIn(pin ,acc)
getPin(acc) : actlPin
Account #
comparePin
(pin,actlpin) : boolean
Submit
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 109
Sample Scenario
AddStudentUI
StudentController
Student
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 110
Sample Scenario
:AddStudent :Student
UserIinterface Controller
add(id,details) <<create>> :Student
add(id,details)
validate( id)
Invalid status
alt Invalid status
update(details)
Updated status
status
<<destroy>>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 111
State Transition Diagram
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 112
State chart Diagram – An ATM Example
[Auth–good] Processing
[invalid I/p]
[Insert card]
Dispensing
Idle [Auth–failed]
Notifying
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 113
Order-Example
start
get first item
/
e]
bl
va ed
ila
s a iv
activity
m ece
Delivered
ite R
[a Item
ll
Item Received
transition
[some items not in stock]
Waiting Delivered
self-transition state
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 114
stop
History State – Example
Idle
Washing
Washing
[ Washing completed ] Sequential sub state
Rinsing
Drying
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 115
In Summary…
Modelling
Requirement Analysis
Class Diagram
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 116