Introduction to Object Modeling
Object-oriented analysis (OOA) – an
approach used to
1. study existing objects to see if they can be reused or
adapted for new uses
2. define new or modified objects that will be combined
with existing objects into a useful business
computing application
Object modeling – a technique for identifying
objects within the systems environment and the
relationships between those objects.
Object Oriented Analysis and Design
1
Introduction to the UML
Unified Modeling Language (UML) – a
set of modeling conventions that is used to
specify or describe a software system in
terms of objects.
– The UML does not prescribe a method for
developing systems—only a notation that is
now widely accepted as a standard for object
modeling.
Object Oriented Analysis and Design
2
Analysis and Design
• Analysis
• Design
– Captures requirements
and problem domain
– What to do
– Creates analysis
models
•
•
Use case view
Static class view
– Makes strategic and
tactical decisions to
meet requirements
– How to do it (above
code level)
– Creates design models
•
•
•
Static class view
State machine view
Interaction view
Object Oriented Analysis and Design
3
Contributions to the UML
Harel
Meyer
Before and after
conditions
Statecharts
Gamma, et al
Frameworks and patterns,
HP Fusion
Booch
Operation descriptions and
message numbering
Booch method
Embley
Rumbaugh
Singleton classes and
high-level view
OMT
Jacobson
Wirfs-Brock
OOSE
Responsibilities
Shlaer - Mellor
Object lifecycles
Odell
Classification
Object Oriented Analysis and Design
4
Basic Principles of Object
Orientation
Object Oriented Analysis and Design
Hierarchy
Modularity
Encapsulation
Abstraction
Object Orientation
5
What is Abstraction?
Salesperson
Not saying
Which
salesperson
– just a
salesperson
in general!!!
Customer
Product
Manages Complexity
Object Oriented Analysis and Design
6
What is Encapsulation?
• Hide implementation from clients
– Clients depend on interface
How does an object encapsulate?
What does it encapsulate?
Improves Resiliency
Object Oriented Analysis and Design
7
What is Modularity?
• The breaking up of something complex
into manageable pieces
Order
Entry
Order Processing
System
Order
Fulfillment
Billing
Manages Complexity
Object Oriented Analysis and Design
8
What is Hierarchy?
Increasing •
abstraction
BankAccount
Savings Checking
Decreasing
abstraction
Asset
Levels of abstraction
Security
Stock
RealEstate
Bond
Elements at the same level of the hierarchy
should be at the same level of abstraction
Object Oriented Analysis and Design
9
Objects, Attributes, & Instances
Object – something that is or is capable of being seen,
touched, or otherwise sensed, and about which users store
data and associate behavior.
–
–
–
–
Person, place, thing, or event
Employee, customer, instructor, student
Warehouse, office, building, room
Product, vehicle, computer, videotape
Attribute – the data that represent characteristics of interest
about an object.
Object instance – each specific person, place, thing, or
event, as well as the values for the attributes of that object.
Object Oriented Analysis and Design
10
What is an Object?
• Informally, an object represents an entity, either
physical, conceptual, or software
– Physical entity
Truck
– Conceptual entity
Chemical Process
– Software entity
Linked List
Object Oriented Analysis and Design
11
A More Formal Definition
• An object is a concept, abstraction, or
thing with sharp boundaries and meaning
for an application
• An object is something that has:
– State
– Behavior
– Identity
Object Oriented Analysis and Design
12
Representing Objects
• An object is represented as rectangles
with underlined names
: Professor
Class Name Only
a + b = 10
ProfessorClark
Professor Clark
Object Name Only
ProfessorClark :
Professor
Class and Object Name
Object Oriented Analysis and Design
13
What is a Class?
• A class is a description of a group of
objects with common properties
(attributes), behavior (operations),
relationships, and semantics
– An object is an instance of a class
• A class is an abstraction in that it:
– Emphasizes relevant characteristics
– Suppresses other characteristics
OO Principle: Abstraction
Object Oriented Analysis and Design
14
Sample Class
Class
Course
Properties
Name
Location
Days offered
Credit hours
Start time
End time
a + b = 10
Object Oriented Analysis and Design
Behavior
Add a student
Delete a student
Get course roster
Determine if it is full
15
Representing Classes
• A class is represented using a
compartmented rectangle
a + b = 10
Professor
Professor Clark
Object Oriented Analysis and Design
16
Class Compartments
• A class is comprised of three sections
– The first section contains the class name
– The second section shows the structure (attributes)
– The third section shows the behavior (operations)
Class Name
Attributes
Operations
Professor
name
empID
create( )
save( )
delete( )
change( )
Object Oriented Analysis and Design
17
Exercise: How many classes could you find here?
VTOL
Glider
Helicopter
Jet
Drone
Military
Object Oriented Analysis and Design
Turboprop
Space Shuttle
Airship
18
What is an Attribute?
Object
Class
Attribute
Attribute Value
:CourseOffering
CourseOffering
number = 101
startTime = 900
endTime = 1100
number
startTime
endTime
:CourseOffering
number = 104
startTime = 1300
endTime = 1500
Object Oriented Analysis and Design
19
What is an Operation?
CourseOffering
Class
Operation
addStudent
deleteStudent
getStartTime
getEndTime
Object Oriented Analysis and Design
20
What is Polymorphism?
• The ability to hide many different
implementations behind a single interface
Manufacturer B
Manufacturer A
Manufacturer C
OO Principle:
Encapsulation
Object Oriented Analysis and Design
21
What is an Interface?
• Interfaces formalize polymorphism
• Interfaces support “plug-and-play”
architectures
Tube
<<interface>>
Shape
Pyramid
Draw
Move
Scale
Rotate
Cube
Object Oriented Analysis and Design
22
Inheritance (cont.)
Object Oriented Analysis and Design
23
Generalization/Specialization,
Supertype, and Subtype
Generalization/specialization – a technique wherein the attributes
and behaviors that are common to several types of object classes are
grouped (or abstracted) into their own class, called a supertype. The
attributes and methods of the supertype object class are then inherited
by those object classes.
Supertype – an entity that contains attributes and behaviors that are
common to one or more class subtypes.
– Also referred to as abstract or parent class.
Subtype – an object class that inherits attributes and behaviors from a
supertype class and then may contain other attributes and behaviors
that are unique to it.
– Also referred to as a child class and, if it exists at the lowest level of the
inheritance hierarchy, as concrete class.
Object Oriented Analysis and Design
24
UML Representation of
Generalization/Specialization
Object Oriented Analysis and Design
25
Exercise: Refine the number of classes here?
VTOL
Glider
Helicopter
Jet
Drone
Military
Object Oriented Analysis and Design
Turboprop
Space Shuttle
Airship
26
Inheritance Relationship
• A class can Inherit the instance variables, interfaces, and
instance methods of another class.
• The class inherit them as if they were defined in the
class.
– A class providing the inheritance is a base class
– The class getting the inheritance is a derived class
• A derived class can override/extend the base class
– The base class methods can be redefined
– The base class can define new variables and methods
• A derived class can be used anyplace a base class can
be used.
– The derived class ISA a base class.
Object Oriented Analysis and Design
27
Multiple Inheritance
Relationship
• A derived class can inherit from multiple base
classes
– It will contain all the variables and methods of every
base class.
– The derived class ISA base class for every base class
inherited
•
This class can be used any place any of the original base
classes could be used.
Object Oriented Analysis and Design
28
Object/Class Relationships
Object/class relationship – a natural
business association that exists between
one or more objects and classes.
Object Oriented Analysis and Design
29
Multiplicity and UML Multiplicity Notations
Multiplicity –
the minimum
and maximum
number of
occurrences
of one
object/class
for a single
occurrence of
the related
object/class. Object Oriented Analysis and Design
30
Aggregation
Aggregation – a relationship in which one larger “whole” class contains
one or more smaller “parts” classes. Conversely, a smaller “part” class is
part of a “whole” larger class.
Object Oriented Analysis and Design
31
Composition
Composition –
an aggregation
relationship in
which the “whole”
is responsible for
the creation and
destruction of its
“parts.” If the
“whole” were to
die, the “part”
would die with it.
Object Oriented Analysis and Design
32
Contains Relationship
• A class can contain another class.
• The class contains another class by having an Instance
Variable of the class in it’s specification
• The composition of classes into a single class allow a
simpler abstraction to be defined for a highly complex
group of classes.
• Example: HomeStereoSystem
Class HomeStereoSystem
{
Tuner
itsTuner;
CDPlayer
itsCDPlayer;
Equalizier itsEqualizer;
Object Oriented Analysis and Design
33
};
Messages
Message – communication that occurs when one object
invokes another object’s method (behavior) to request
information or some action
Object Oriented Analysis and Design
34
Polymorphism
• Polymorphism means “Many Form”
• Two objects are polymorphic if they have
the same interface and different behavior.
• This allows clients to use them without
knowing their true behavior.
Object Oriented Analysis and Design
35
Polymorphism
Polymorphism – literally
meaning “many forms,” the
concept that different
objects can respond to the
same message in different
ways.
Override – a technique
whereby a subclass
(subtype) uses an attribute
or behavior of its own
instead of an attribute or
behavior inherited from the
class (supertype).
Object Oriented Analysis and Design
36
Relationships: Association
• Models a semantic connection among
classes
Association
Name
Professor
Works for
Association
Class
University
Role Names
University
Professor
Employee Employer
Object Oriented Analysis and Design
37
Uses Relationship
• A class uses another class without containing it.
• The class gets access to the object when it’s
passed to a class interface as an argument.
• Example:
HomeStereoSystem::Play(CD&)
• The play interface of HomeStereoSystem takes
a Compact Disc (CD) object which it can use.
Object Oriented Analysis and Design
38
Abstract Classes
• Used to hold common operations and data
• Used in inheritance hierarchy
– Derived (child) classes provide implementations
• Documented with class name in italics
– Can also use {abstract} property
Shape
{abstract}
+move()
+erase() : void {abstract}
+draw() : void {abstract}
Shape
+move()
+erase() : void
+draw() : void
Circle
Rectangle
Triangle
+draw() : void
+erase() : void
+draw() : void
+erase() : void
+draw() : void
+erase() : void
Object Oriented Analysis and Design
39
UML Interfaces
• Abstract class with 0 methods or data is
an interface
• Defines public behavioral contract
• Says nothing about the implementation
– May be implemented by one or more classes
– Implementation called a realization
– This is how COM works
• Documented with <<interface>> keyword
Object Oriented Analysis and Design
40
Operation Signatures
• The "signature" of an operation is the
combination of its:
– name
– parameters
• Operations with the same signature are the
same operation
– Must be in different classes
• Operations with different signatures are different
operations
– Can be in the same class
Object Oriented Analysis and Design
41
Overloading Operations
• Many OO languages allow operations to be
overloaded
– The name is the same, but the parameters are
different
• A class can implement an operation in different
ways depending on the number and type of
parameters
• Example
void print(String& text){…}
void print(String& text,
ostream& output){…}
Object Oriented Analysis and Design
42
Modeling with UML Interaction
Diagrams
• Two types of Interaction Diagrams
– Communication Diagrams
• In UML 1.x, called Collaboration Diagrams
– Sequence Diagrams
• The two types are semantically equivalent
• Difference is on what each emphasizes
– Communication – Class relationships
– Sequence – Time sequences
Object Oriented Analysis and Design
43
UML Communication Diagrams
• Visually shows object relationships
• Useful for showing the structure of an
algorithm
– i.e. Nested interactions are clearly shown
Object Oriented Analysis and Design
44
Diagram Elements
• Objects
• Messages
– One-way
communication
– Messages to other
objects
– Messages to self
• Sequence numbers
• Conditionals
• Iteration
Object Oriented Analysis and Design
45
UML Communication Diagram
Example
c o m m L o a d In itia l S ta te
M e n u s e le c t(L o a d
W o rld )
2 : V e rify file e x is ts
: U s e r IO
: F ile IO
1 : S ta rt u s e c a s e
3 : O p e n file
4 : P a s s o p e n file s tre a m
: W o rld C O
5 : C re a te n e w w o rld
6 : R e a d w o rld c o n te n ts
: W o rld
Object Oriented Analysis and Design
46
UML Communication Diagram
Options
• Sequence numbers
– Can be flat or nested
• 1, 2, 3, … or 1, 2, 2.1, 2.2, 2.2.1, 3, …
• Nested (Dewey decimal) specified by UML
– Can contain letters indicating thread of control
• A2, A3, B2, B3
• Messages can contain guards
– Conditional execution
– 4 : [condition] some operation
• Classes can communicate with
themselves Object Oriented Analysis and Design
47
Using Communication Diagrams
• Model a single instance through a
scenario
• Use separate diagrams or parts of
diagrams to model alternate scenarios
Object Oriented Analysis and Design
48
Sequence Diagram Elements
• Time
• Objects
• Object Lifelines
– Object creation
– Object destruction
• Object Activity
• Messages
– Messages to other
objects
– Messages to self
•
•
•
•
Synchronization
Returns
Conditionals
Iteration
Object Oriented Analysis and Design
49
Sequence Diagram Basics
• Time moves down
– Time is relative
– Exact timings require a Timing Diagram
• Lifeline shows when object is active on
stack
– Dashed line when inactive
– Double line when active
Object Oriented Analysis and Design
50
UML Sequence Diagram
Example
sd Load Initial State
Use Case Name
Participant
: User IO
: File IO
: World CO
Lifeline
Specify File Name
Activ
a
tion
sh o w
(may ion)
ll
a
c
Self
tivat
ed ac
stack
Verify File Exists
ga
Passin ter
e
p a ra m
Open File
ReadNewWorld( Open File Handle )
: World
<<create>>
Read World Contents
R
rn
etu
Object Oriented Analysis and Design
51
Sequence Diagram Options
• Return arrows are optional
– Data on return arrows is optional
• Stack activation lines for recursion or self-calls
• Arrow format is important
– Synchronous flow: solid line, filled arrowhead
– Asynchronous flow: solid line, stick or half arrowhead
(UML 1.3)
– Return: dashed line, stick arrowhead
• Messages can have guards
• Variable names
• Parameter values
Object Oriented Analysis and Design
52
Using Sequence Diagrams
• Model a single instance through a
scenario
• Use separate diagrams or parts of
diagrams to model alternate scenarios
Object Oriented Analysis and Design
53
When to use Sequence
Diagrams
• Model the behavior of collaborating
objects over time
• Model behavior of several objects in a
single use case
• Visualizing collaborations between several
objects
Object Oriented Analysis and Design
54
UML Activity Diagrams
• Diagram elements:
–
–
–
–
–
–
Start and End symbols
Activities
Forks and Joins
Branches and Merges
Guards
Swimlanes
Object Oriented Analysis and Design
55
Activity Diagram Example
F u lfu llm e n t
P a rtitio n
(s w im la n e )
C u s to m e r S e rv ic e
F in a n c e
S ta rt
R e c e iv e O rd e r
F o rk
c o rn e rs
R ounded
ss)
(n o t a c la
Con
d it io
S e n d In v o ic e
F ill O rd e r
nal
D
s io
eci
n
[p rio rity o rd e r]
[e ls e ]
O v e rn ig h t D e liv e ry
Me
R e c e iv e P a y m e n t
R e g u la r D e liv e ry
rg e
g a te )
J o in (A N D
C lo s e O rd e r
End
Object Oriented Analysis and Design
56
Example of an Activity Diagram
Object Oriented Analysis and Design
57
When to Use Activity Diagrams
•
•
•
•
Analyzing a use case
Understanding workflow
Describing a complicated algorithm
Modeling multithreaded or parallel
behavior
Object Oriented Analysis and Design
58
UML State Diagrams
• Diagram elements:
– Start and End symbols
– States
• May have an associated activity
– Transitions
• Event
• Guard
• Action
Object Oriented Analysis and Design
59
State Diagram Example
Start
End
order processing
system started
Tr
a
ns
iti
on
order processing
system stopped
order processed
order cancelled
Waiting
Trigg
e
r
receive order [amount <= $25]
receive order [amount > $25]
C
on
di
tio
St
at
e
ge
r
Ac
tiv
ity
n
ig
Tr
approved / debit account
Processing Order
credit rejected
Checking Credit
Object Oriented Analysis and Design
Canceling Order
60
When to use State Diagrams
• DON'T use them for every class in the
system
• Describing the behavior of an object
across several use cases
• When a system is heavily event-driven
Object Oriented Analysis and Design
61
Descargar

(Advanced) Object-Oriented Analysis and Design Workshop