-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
1/71
OO programming and UMLOO programming and UML
DesignDesign
Dr. Zhen JiangWest Chester University
E-mail: [email protected]
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
2/71
OutlineOutline Introduction to object and class
I
ntroduction to UML Introduction to UML design
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
3/71
Introduction to object and classIntroduction to object and class
Why OO programming? Look at this picture carefully
You need to identify it from VERY similarpictures in the next slide
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
4/71
Introduction to object and classIntroduction to object and class
Why OO programming? Which one is shown before?
In the next slide, your partner will see theselected picture and other two picturestogether. Write down something to help yourpartner to pick up the same picturecorrectly.
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
5/71
Introduction to object and classIntroduction to object and class
Why OO programming? Partners job
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
6/71
Introduction to object and classIntroduction to object and class
Why OO programming? Which one?
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
7/71
Introduction to object and classIntroduction to object and class
Why OO programming? From snapshot to the action
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
8/71
Introduction to object and classIntroduction to object and class
Why OO programming? From snapshot to the action
3
2
1
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
9/71
Introduction to object and classIntroduction to object and class
Whats object Identity
State
Behavior
S
equence Diagram Statechart Diagram
Messages and methods
Whats class Objects and Classes
Class Attributes
Operation (Method)
Interfaces
Interfaces and Implementation
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
10/71
Wh
ats objectWh
ats object
Fundamentals ofObject-Oriented
Programming
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
11/71
Whats objectWhats object
Conceptually, there are many ways to thinkof an object
something that can be seen or touched
a thing to which some action is directed something that performs an action
The structure and behaviour of similar
objects are defined in their common class
Objects have three properties: identity , state,
and behaviour
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
12/71
Object Property 1:Object Property 1: IdentityIdentity
Identity is that property of an object whichdistinguishes it from all other objects
Most programming languages use variable
names to refer to objects Keep in mind, however, that an object may
not have a name; Similarly, an object might
have multiple names (aliases) For this reason, there is a subtle distinction
made between the concepts of "name" and
"identity"
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
13/71
Object Property 2: StateObject Property 2: State
The state of an object encompasses all of thedescriptions of the object plus the current
values of each of these descriptions
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
14/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
15/71
Example ObjectsExample Objects
There are many physical objects we canexamine right in this room
each person is an object
any chair is not an object each light bulb is an object
Any book is not an object
this room itself is an object (full or not)
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
16/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
17/71
Whats the relationship amongWhats the relationship among
objects: Messages and Meth
odsobjects: Messages and Meth
ods A object executes a method when it
sends/receives a message
For example, we can ask/tell a dog to sit bysending him the message "sit"
In object-oriented programming, objects
send messages asking/telling others toperform behaviors -- those other objects
invoke the method corresponding to the
message in order to execute the desired
behavior
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
18/71
Whats classWhats class
A class describes the common structure(attributes/state) and behaviour of its instances
For example,
3.14, 2.71, and 5.5 can be classified as Floats
the following shapes can be classified as Circles
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
19/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
20/71
Classes and objectsClasses and objects
How would we describe the state, behaviour,and identity for each of these objects
We have looked at objects and we have seen
that objects can be "classified" into classes As programmers, we work with both classes
and objects from those classes
For example, we might write a stack classand create multiple stack objects for use in
our program
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
21/71
In a 2D drawing package, circles have aradius, a line thickness, a line colour, and a
fill colour
Each individual circle (instance) drawn bythe user has its own value for each attribute
The programmer writes a Circle class and
the program instantiates a Circle objectevery time the user draws a Circle
a snowman made from 9
Circle instances
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
22/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
23/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
24/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
25/71
Interface and ImplementationInterface and Implementation
The class interface is its external (public)view
The class implementation is its internal
(private) view It is convenient to think of the interface as
describing "what the objects of this class can
do" and the implementation as "how the
objects of this class do it"
The implementation of a class consists of all
the "behind the scenes" operations defined
in the interface of the class
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
26/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
27/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
28/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
29/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
30/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
31/71
UML OverviewUML Overview
UML is a language for visualizing,specifying, constructing and documenting
the artifacts of a software system
The artifacts might include requirements,architecture, design, source code, project
plans, tests, prototypes, releases
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
32/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
33/71
Light
On Off Turn on/off
True False
Turn_on
attributes: {True,
False}
operations/methods:
value
structure
Turn_off
Turn_on/off ( )
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
34/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
35/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
36/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
37/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
38/71
Hiding DetailHiding Detail
Circle
area()
display()
Circle
radius: float
center_x: int
center_y: int
Circle
You can optionally leave out the attributes,operations, or both in a class icon:
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
39/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
40/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
41/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
42/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
43/71
Class RelationshipsClass Relationships
Generalization Association
Association Class
Qualified Association
Ternary Association
Aggregation
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
44/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
45/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
46/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
47/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
48/71
AssociationAssociation
Associations can be adorned with the multiplicity.
4..*Faculty Student
1
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
49/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
50/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
51/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
52/71
AggregationAggregation
An aggregation is an association thatrepresents whole/part relationship
The whole end of the association
relationship is adorned with an opendiamond shape (e.g. X is part of Y)
e.g. door:Door is part of car:Car
X Y
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
53/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
54/71
ConstraintsConstraints
Constraints on Object
Constraints on Relations (Ordering)
General Constraints (Dependency)
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
55/71
Constraints on ObjectConstraints on Object
The constraints restricts the values thatobjects can be.
Example: No employees salary can exceedthe salary of the employees boss.
Employee
Sa
la
ry
Employer
Sa
la
ry
{salary
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
56/71
Constraints on RelationsConstraints on Relations
(Ordering)(Ordering)
{Order} indicates that the elements of themany end of an association have an explicitorder that must be preserved.
Paper Author
{ordered}
11..
*
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
57/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
58/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
59/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
60/71
UML class diagram is not objectUML class diagram is not object
diagramdiagram
Customer BankLoan
Other-Loan
Should we add relationbetween Bank and Other-Loans?Can Bank change Other-loans?
Instance of Loan and Other-Loans?
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
61/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
62/71
UML class diagram is not dataUML class diagram is not data
flow chartflow chart
Customer Dealer
Product Manager
buy sell report
bargain
authorize
sign
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
63/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
64/71
How to describe theHow to describe the
beh
aviors/actions of objects inbeh
aviors/actions of objects inUML class diagramUML class diagram
?
Person
sSNaddressemail
Faculty StudentCustomer Casher
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
65/71
How to describe theHow to describe the
beh
aviors/actions of objects inbeh
aviors/actions of objects inUML class diagramUML class diagram
Use case (stories): Each use case defines an interaction
between an actor and the system
Use case
Use case
Use case
Use case
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
66/71
Scenarios of a use case Reception
Check
Failure
Authorized
Waiting
Success Failure
?
Order
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
67/71
How to describe theHow to describe the
beh
aviors/actions of objects inbeh
aviors/actions of objects inUML class diagramUML class diagram
In design, see
www.cs.wcupa.edu/~zjiang/intro_uc.ppt.
In programming, see time sequence
diagram, see
www.cs.wcupa.edu/~zjiang/intro_TS
.ppt.
Wh t ki d f l ti hi iWh t ki d f l ti hi i
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
68/71
What kind of relationship isWhat kind of relationship is
generalizationgeneralization
People
Student
x: inty: int
radius: doubleRectangle
PositionPoint
Circle
PositionPoint
*Tip 4: Class A is a super class of class B if and only if anyobject of class B can also play the role as an object of class A.
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
69/71
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
70/71
H t k th i t fH t k th i t f
-
8/7/2019 Csc589 Intro OO-OBJECT ORIENTED ANALYSIS AND DESIGN
71/71
How to keep the consistency ofHow to keep the consistency of
all the constraintsall the constraints
Ticket-buyer Dependent
Traveler
1 0..60..1