Chapter 2 UML Overview








Building blocks of the UML
Structure things in the UML
Behavioral things in the UML
Grouping things in the UML
Relationships in the UML
Diagrams in the UML
Extension mechanism of the UML
Simple Example - Hello World
Object Oriented Analysis and Design
1
Building Blocks of the UML
Object Oriented Analysis and Design
2
Building Blocks of the UML
 The vocabulary of the UML encompasses
three kinds of building blocks:
 Things: the abstractions that are first-class
citizens in a model;
 Relationships: relationships tie these things
together;
 Diagrams: diagrams group interesting
collections of things.
Object Oriented Analysis and Design
3
Things in the UML
 There are four kinds of things in the UML:
 Structural things: class, interface, collaboration,
use case, active class, component, artifact &
node
 Behavioral things: interaction, state machine,
activity
 Grouping things: package
 Annotational things: note
 These things are the basic object-oriented
building blocks of the UML.
Object Oriented Analysis and Design
4
Structural things in the UML
Object Oriented Analysis and Design
5
Structural things in the UML
 the nouns of UML models.
 the mostly static parts of a model, either
conceptual or physical
 Collectively, the structural things are called
classifiers
 eight kinds:




Logic view: class, interface, collaboration,
Requirement view: use case
Process view: active class
Implementation view: component, artifact, node
Object Oriented Analysis and Design
6
Structural things - Class
 A class is a description of a set of objects
that share the same attributes, operations,
relationships, and semantics.
 A class is represented using a
compartmented rectangle
Professor
Objects
Attributes
Professor Smith
Professor Mellon
Professor Jones
Object Oriented Analysis and Design
Operations
7
- name
- employeeID : UniqueId
- hireDate
- status
- discipline
- maxLoad
+ submitFinalGrade()
+ acceptCourseOffering()
+ setMaxLoad()
+ takeSabbatical()
Review: 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
Object Oriented Analysis and Design
Professor
name
empID
create( )
save( )
delete( )
change( )
8
Review: Representing Objects
 An object is represented as rectangles with
underlined names
: Professor
ProfessorClark
a + b = 10
Class Name Only
ProfessorClark :
Professor
Professor Clark
Object Name Only
Class and Object Name
Object Oriented Analysis and Design
9
Structural things - Interface
 An interface is a collection of operations
that specify a service of a class or
component.
 Interfaces support “plug-and-play”
architectures
Tube
<<interface>>
Shape
Pyramid
Draw
Move
Scale
Rotate
Cube
Realization relationship
Object Oriented Analysis and Design
10
Review: Interface Representations
Tube
Elided/Iconic
Representation
(“lollipop”)
Pyramid
Shape
Canonical
(Class/Stereotype)
Representation
Object Oriented Analysis and Design
Cube
Tube
<<interface>>
Shape
Pyramid
Draw
Move
Scale
Rotate
Cube
11
Structural things - Collaboration
 In the context of a system's architecture, a
collaboration allows you to name a conceptual
chunk that encompasses both static and
dynamic aspects.
 A collaboration names a society of classes,
interfaces, and other elements that work
together to provide some cooperative behavior
that's bigger than the sum of all its parts.
 You use collaborations to specify the
realization of use cases and operations, and to
model the architecturally significant
mechanisms of your system.
Object Oriented Analysis and Design
12
Structural things - Collaboration
 A collaboration is a society of classes, interfaces,
and other elements that work together to provide
some cooperative behavior that's bigger than the
sum of all its parts.
 A collaboration is also the specification of how an
element, such as a classifier (including a class,
interface,component, node, or use case) or an
operation, is realized by a set of classifiers and
associations playing specific roles used in a specific
way.
 Graphically, a collaboration is rendered as an ellipse
with dashed lines.
Login
Object Oriented Analysis and Design
Login
13
Structural things – Use Case
 a use case is a description of set of sequence of
actions that a system performs that yields an
observable result of value to a particular actor.
 A use case is used to structure the behavioral things
in a model.
 A use case is realized by a collaboration.
 Graphically, a use case is rendered as an ellipse with
solid lines, usually including only its name.
Login
Object Oriented Analysis and Design
Login
14
Structural things – Active Class
 an active class is a class whose objects own one or
more processes or threads and therefore can initiate
control activity.
 An active class is just like a class except that its
objects represent elements whose behavior is
concurrent with other elements.
 Graphically, an active class is rendered as a class
with double lines on the left and right; it usually
includes its name, attributes, and operations.
EventManager
suspend()
flush()
Object Oriented Analysis and Design
15
Structural things – Component
 A component is a modular part of the system
design that hides its implementation behind a
set of external interfaces.
 The implementation of a component can be
expressed by wiring together parts and
connectors.
 Graphically, a component is rendered like a
class with a special icon in the upper right
corner.
Orderform
Object Oriented Analysis and Design
16
Structural things – Artifact
 An artifact is a physical and replaceable part of
a system that contains physical information
("bits").
 An artifact typically represents the physical
packaging of source or run-time information.
 Graphically, an artifact is rendered as a
rectangle with the keyword «artifact» above
the name.
<<artifact>>
Login.dll
Object Oriented Analysis and Design
17
Structural things – Node
 a node is a physical element that exists at run time
and represents a computational resource, generally
having at least some memory and, often, processing
capability.
 A set of components may reside on a node and may
also migrate from node to node.
 Graphically, a node is rendered as a cube, usually
including only its name.
<<Node>>
Node #1
Object Oriented Analysis and Design
18
Behavioral things in the UML
Object Oriented Analysis and Design
19
Behavioral things in the UML
 the verbs of UML models.
 the mostly dynamic parts of a model
 three primary kinds:
 Among a set of objects: interaction
 For an object: state machine
 The sequence of steps: activity
Object Oriented Analysis and Design
20
Behavioral things - Interaction
 an interaction is a behavior that comprises a set of
messages exchanged among a set of objects
within a particular context to accomplish a specific
purpose.
 The behavior of a society of objects or of an
individual operation may be specified with an
interaction.
 An interaction involves a number of other elements,
including messages, action sequences (the
behavior invoked by a message), and links (the
connection between objects).
 Graphically, a message is rendered as a directed
line, almost always including the name of its
operation.
display()
Object Oriented Analysis and Design
21
What Is an Interaction Diagram?
 An interaction diagram shows an interaction,
consisting of a set of objects and their
relationships, including the messages that
may be dispatched among them.
 It models the dynamic aspects of a system.
Sequence Diagrams
Object Oriented Analysis and Design
Collaboration Diagrams
22
What Is a Sequence Diagram?
 A sequence diagram is an interaction
diagram that emphasizes the time ordering
of messages.
 The diagram shows
 The objects participating in the interaction.
 The sequence of messages exchanged.
Sequence Diagrams
Object Oriented Analysis and Design
23
What Is a Communication Diagram?
 A communication diagram emphasizes the
organization of the objects that participate in
an interaction.
 The communication diagram shows
 The objects participating in the interaction.
 Links between the objects.
 Messages passed between the objects.
Communication Diagrams
Object Oriented Analysis and Design
24
Interaction Diagram Example - HelloWorldApp2.java
public class HelloWorldApp2 {
public static void main(String[] args) {
Greeting hello = new Greeting();
hello.greet("Hello World");
}
}
class Greeting {
public void greet(String s) {
System.out.println(s);
}
}
client
Object Oriented Analysis and Design
1: greet(String)
client
hello : Greeting
greet(String)
hello : Greeting
25
Behavioral things - State machine
 a state machine is a behavior that specifies the
sequences of states an object or an interaction
goes through during its lifetime in response to
events, together with its responses to those events.
 The behavior of an individual class or a
collaboration of classes may be specified with a
state machine.
 A state machine involves a number of other
elements, including states, transitions, events, and
activities.
 Graphically, a state is rendered as a rounded
rectangle, usually including its name and its
substates, if any.
waiting
Object Oriented Analysis and Design
26
Behavioral things - Activity
 an activity is a behavior that specifies the
sequence of steps a computational process
performs
 In an activity, the focus is on the flows among
steps without regard to which object performs
each step.
 A step of an activity is called an action.
 Graphically, an action is rendered as a rounded
rectangle with a name indicating its purpose. States
and actions are distinguished by their different
contexts.
waiting
Object Oriented Analysis and Design
27
Grouping things in the UML
Object Oriented Analysis and Design
28
Grouping things in the UML
 A package is a general-purpose mechanism for
organizing elements into groups.
 In all, there is one primary kind of grouping thing,
namely, packages.
 Packages are the basic grouping things with which
you may organize a UML model. There are also
variations, such as frameworks, models, and
subsystems (kinds of packages)
Bus ines s rules
Object Oriented Analysis and Design
29
Grouping things - Package
 Grouping things are the organizational parts of UML
models.
 Structural things, behavioral things, and even other
grouping things may be placed in a package.
 Unlike components (which exist at run time), a
package is purely conceptual (meaning that it exists
only at development time).
 Graphically, a package is rendered as a tabbed
folder, usually including only its name and,
sometimes, its contents.
A
B
(from
packageA)
(from
packageB)
PackageA
PackageB
Dependency relationship
Object Oriented Analysis and Design
30
Annotational things - Note





Annotational things are the explanatory parts of UML models.
These are the comments you may apply to describe,
illuminate, and remark about any element in a model.
There is one primary kind of annotational thing, called a note.
A note is simply a symbol for rendering constraints and
comments attached to an element or a collection of elements.
Graphically, a note is rendered as a rectangle with a dogeared corner, together with a textual or graphical comment.
One of these is
executed:
Object Oriented Analysis and Design
31
Relationships in the UML
Object Oriented Analysis and Design
32
Relationships in the UML
 There are four kinds of relationships in the UML:




Association
Dependency
Generalization
Realization
Window
+ open() : void
<<Interface>>
AbstractWindow
+ close() : void
+ open() : void
+ handleEvent(e: Event) : void
+ close() : void
Event
ConsoleWindow
Object Oriented Analysis and Design
DialogBox
Control
33
What Is an Association?
 The semantic relationship between two
or more classes that specifies
connections among their instances
 A structural relationship, specifying that objects of
one thing are connected to objects of another
<<entity>>
Student
Association
Name
Professor
Object Oriented Analysis and Design
<<entity>>
Schedule
<<entity>>
Course
Role Names
Works for
Employee Employer
Association
34
University
What Is an Association? – A example
class CatalogueEntry {
private string name;
private int number;
private double cost;
public double getCost () {
return cost;
}
}
class Part {
private CatalogueEntry
entry;
public double cost () {
return entry.getCost();
}
}
Object Oriented Analysis and Design
CatalogueEntry screw= new
CatalogueEntry
(“screw”, 28834,
0.02);
Part screw1 = new Part(screw) ;
screw1.cost();
35
What Is an Association? – A example
 An association is a structual relationship that desribes a set of
links.
 a link being a connection among objects.
Describes
: CatalogueEntry
name = “screw”
number = 28834
Fig. Links between objects cost = 0.02
: Part
Describes
: Part
 A link specifies a path along which one object can dispatch a
message to another (or the same)object.
: CatalogueEntry
Client
cost()
getCost()
: Part
Fig. Finding the cost of a Part
Object Oriented Analysis and Design
36
name = “screw”
number = 28834
cost = 0.02
What Is an Association? – A example
 In general, a link is an instance of an
association.
CatalogueEntry
- name
- number
- cost
Part
*
+ cost()
1
+ getCost()
Fig. Example of an association
Object Oriented Analysis and Design
37
Example : Associations mapping to VB
‘ Schedule.cls
Schedule
Public theStudent as Student
1
1
Student
Object Oriented Analysis and Design
‘ Student.cls
Public theSchedule as Schedule
38
Adornments that apply to associations.
 An association name: to describe the nature of the
relationship.
 When a class participates in an association, it has a specific
role that it plays in that relationship. A role is just the face the
class at the near end of the association presents to the class at
the other end of the association.
Association
Name
Person
job
nn
nn
-employee
-employer
Role Names
Object Oriented Analysis and Design
39
Company
Adornments that apply to associations.
 The multiplicity of an association's role: to state how many
objects may be connected across an instance of an association.
 Navigation: Given a plain, unadorned association between two
classes, it's possible to navigate from objects of one kind to
objects of the other kind.
 Unspecified
 Exactly one
1
 Zero or more (many,
0..*
unlimited)
*
 One or more
1..*
 Zero or one
0..1
 Specified range
2..4
 Multiple, disjoint
2, 4..6
ranges
Object Oriented Analysis and Design
Multiplicity
University
1
Navigation
40
0..*
Professor
Association - Aggregation
 A special form of association that models a
whole-part relationship between an
aggregate (the whole) and its parts
Whole
Part
Schedule
Student
Aggregation
Object Oriented Analysis and Design
41
Association - Composition
 A form of aggregation with strong
ownership and coincident lifetimes
 The parts cannot survive the whole/aggregate
Part
Whole
Student
Schedule
Composition
Object Oriented Analysis and Design
42
Association - Association Class
 In an association between two classes, the
association itself might have properties.
 A class “attached” to an association
 Contains properties of a relationship
 One instance per link
Company
*
-employer
1..*
-employee
Job
-salary
+ getSalary()
Object Oriented Analysis and Design
43
Person
Association - Association Class
Company
*
-employer
Person
1..*
-employee
Job
-salary
+ getSalary()
Design Decisions
Company
Object Oriented Analysis and Design
1
1..*
Job
-salary
+ getSalary()
44
*
1
Person
Association - Recursive association
prerequisites
0..*
Course
Object Oriented Analysis and Design
45
Association - Example
0..1
has
School
Department
1
1..n
1..n
1..n
1..n
assignedTo
member
-chairperson
1..n
n
attends
Student
n
Object Oriented Analysis and Design
1..n
teaches
Course
n
n
46
1..n
0..1
Instructor
Relationships: Dependency
 A relationship between two model elements
where a change in one may cause a
change in the other
 Non-structural, “using” relationship
Client
Class
Package
ClientPackage
Object Oriented Analysis and Design
Supplier
Client
Dependency
relationship
SupplierPackage
47
Componen
t
Supplier
Dependency
relationship
Dependency – Example
Course
Professor
class Professor {
public void teach(Course c) { ……..}
……………..
}
class Professor {
public void teach() { Course c = new Course(); ……..}
……………..
}
Object Oriented Analysis and Design
48
Example: HelloWorld.java
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("Hello World!", 50, 25);
}
}
Applet
Dependency relationship
Graphics
HelloWorld
paint()
Object Oriented Analysis and Design
49
Relationships: Generalization
 A relationship among classes where one
class shares the structure and/or behavior
of one or more classes
 Defines a hierarchy of abstractions in which
a subclass inherits from one or more
superclasses
Generalization
relationship
 Single inheritance
 Multiple inheritance
 an “is-a-kind of” relationship
Employee
Engineer
Object Oriented Analysis and Design
50
Manager
Generalization - Example
• Employee is a generalization of Engineers and
Managers.
• Engineer is a specialization of Employee.
• Manager is a kind of Employee.
• Engineers and Managers inherit the Employee interface
(and in this case, some implementation too).
class Employee {…...};
class Manager : public Employee {..};
class Engineer : public Employee {…};.
class Employee {…...}
class Manager extends Employee {..}
class Engineer extends Employee {…}
Object Oriented Analysis and Design
51
Example: HelloWorld.java
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("Hello World!", 50, 25);
}
}
Applet
Generalization relationship
Graphics
HelloWorld
paint()
Object Oriented Analysis and Design
52
Example: Single Inheritance
 One class inherits from another
Ancestor
Superclass
(parent)
Account
balance
name
number
Withdraw()
CreateStatement()
Generalizatio
n Relationship
Subclasses
Checking
Savings
Withdraw()
GetInterest()
Withdraw()
Descendents
Object Oriented Analysis and Design
53
Example: Multiple Inheritance
 A class can inherit from several other
classes
Animal
FlyingThing
multiple
inheritance
Airplane
Helicopter
Bird
Wolf
Horse
Use multiple inheritance only when needed, and always with
caution !
Object Oriented Analysis and Design
54
What Gets Inherited?
 A subclass inherits its parent’s attributes,
operations, and relationships
 A subclass may:
 Add additional attributes, operations,
relationships
 Redefine inherited operations (use caution!)
 Common attributes, operations, and/or
relationships are shown at the highest
applicable level in the hierarchy
Inheritance leverages the similarities among classes
Object Oriented Analysis and Design
55
Example: What Gets Inherited
GroundVehicle
weight
licenseNumber
Superclass
(parent)
owner
0..*
Person
1
register( )
generalization
Truck
Car
Subclass
size
tonnage
getTax( )
Object Oriented Analysis and Design
56
Trailer
Relationships: Realization
 One classifier serves as the contract that
the other classifier agrees to carry out
Realization relationship
Tube
Tube
<<Interface>>
Shape
Pyramid
Shape
Cube
draw()
move()
scale()
rotate()
Elided/Iconic
Representation
(“lollipop”)
Object Oriented Analysis and Design
Pyramid
Cube
Canonical
(Class/Stereotype)
Representation
57
Realization - Example
Circle
Shape
interface Shape {
public void draw() ;
}
class Shape {
public:
virtual void draw() = 0 ;
};
class Circle : public Shape {
public:
void draw() {…..}
……
};
class Circle implements Shape {
public void draw() {…..}
……
}
Object Oriented Analysis and Design
58
Diagrams in the UML
Object Oriented Analysis and Design
59
Diagrams in the UML 1.x
 The UML1.x includes nine such diagrams:


Class diagrams: to illustrate logical structure.



Object diagrams: to illustrate objects and links.
State diagrams: to illustrate behavior.
Component diagrams: to illustrate physical structure of
the software.

Deployment diagrams: to show the mapping of software
to hardware configurations.

Interaction diagrams (i.e., collaboration and sequence
diagrams): to illustrate behavior.
  Activity diagrams: to illustrate the flow of events in a usecase.
Object Oriented Analysis and Design
60
A diagram is a view into a model
A model is a complete
description of a system
from a particular
perspective
Activity
Diagrams
Scenario
Scenario
Diagrams
Sequence
Diagrams
Diagrams
Scenario
Scenario
Diagrams
Collaboration
Diagrams
Diagrams
Object Oriented Analysis and Design
State
State
Diagrams
Class
Diagrams
Diagrams
use-case
Diagrams
State
State
Diagrams
Object
Diagrams
Diagrams
State
State
Diagrams
State
Diagrams
Diagrams
Models
Deployment
Diagrams
61
Component
Component
Diagrams
Component
Diagrams
Diagrams
Diagrams in the UML1.x
Modeling Requirements
Use Case diagram - organizing and modeling the behaviors of a system.
Modeling Structure:
Logic View
Class diagram - shows a set of classes, interfaces, and collaborations and their
relationships.
Component diagram - shows the organizations and dependencies among a set of
components.
Physical View
Deployment diagram - shows a set of nodes and their relationships.
Modeling Behavior
Sequence diagram - emphasizes the time ordering of messages.
Collaboration diagram - emphasizes the organization of the objects that
participate in an interaction.
Statechart diagram - emphasizes the event-ordered behavior of an object.
Activity diagram- emphasizes the flow of control among objects.
Object Oriented Analysis and Design
62
Projection of
Interaction
Projection of
state machine
Diagrams in the UML 2.0
 The UML2.0 includes thirteen diagrams:







Class diagram
Object diagrams
Component diagrams
Composite structure diagram
State diagram
Deployment diagram
Interaction diagrams
• communication and sequence diagrams)




Activity diagram.
Package diagram
Timing diagram
Interaction overview diagram
Object Oriented Analysis and Design
63
Diagrams in the UML 2.0
Object Oriented Analysis and Design
64
Diagrams - Class Diagram
 Class diagram shows a set of classes, interfaces,
and collaborations and their relationships
Object Oriented Analysis and Design
65
Diagrams - Class Diagram
 Class diagrams contain:
 Classes, interfaces, collaborations.
 Dependency, generalization, and association relationships
 Captures the vocabulary of a system
 Built and refined throughout development
 Purpose
 Name and model concepts in the system
 Specify collaborations
 Specify logical database schemas
 Developed by analysts, designers, and
implementers
Object Oriented Analysis and Design
66
A Simple Sales Order Example
Order
Product
Ship via
Object Oriented Analysis and Design
67
Class Diagram for the Sales Example
Sale
Salesperson
Customer
seller
buyer
Corporate
Object Oriented Analysis and Design
Product
Vehicle
item sold
Individual
68
Truck
shipping mechanism
Train
Effect of Requirements Change
Suppose you need a new
type of shipping vehicle ...
seller
Sale
buyer
Salesperson
item sold
Customer
Corporate
Product
Truck
Individual
shipping mechanism
Vehicle
Train
Airplane
Change involves adding a new subclass
Object Oriented Analysis and Design
69
Diagrams - Component Diagram
A component diagram shows the organizations and
dependencies among software components, including source
code components, binary code components, and executable
components.
Component diagrams contain:




Component packages.
Components
Interfaces
Dependency relationships
image.java
component.java
ImageObserver
Object Oriented Analysis and Design
70
Diagrams - Component Diagram
 Captures the physical structure of the
implementation
 Built as part of architectural specification
 Purpose
 Organize source code
 Construct an executable release
 Specify a physical database
 Developed by architects and programmers
Object Oriented Analysis and Design
71
Component Diagram - Example
Object Oriented Analysis and Design
72
Component Diagram - Example
Object Oriented Analysis and Design
73
Diagrams - Deployment Diagram
 A deployment diagram is a diagram that shows
the configuration of run time processing nodes
and the components that live on them.
 Captures the topology of a system’s hardware
 Built as part of architectural specification
 Purpose
 Specify the distribution of components
 Identify performance bottlenecks
 Developed by architects, networking engineers,
and system engineers
Object Oriented Analysis and Design
74
Deployment Diagram -Example
Object Oriented Analysis and Design
75
Deployment Diagram -Example
Object Oriented Analysis and Design
76
Diagrams - Sequence Diagram
 A sequence diagram emphasizes the time
ordering of messages.
Supplier Object
Client Object
:Supplier
:Client
Object Lifeline
Reflexive Message
1: doSomething()
1.1: doAnotherthing()
Message
Sequence number
Focus of Control
Object Oriented Analysis and Design
77
Diagrams - Collaboration Diagram
 A collaboration diagram emphasizes the
organization of the objects that participate in an
interaction.
Client Object
Supplier Object
Link
:Client
Message
Object Oriented Analysis and Design
:Supplier
1: doSomething()
78
Sequence Diagram V.S. Collaboration Diagram
 Sequence diagrams and collaboration diagrams
express similar information but show it in
different ways.
 Sequence diagrams show the explicit sequence
of messages and are better for real-time
specifications and for complex scenarios.
 Collaboration diagrams show the relationships
among objects and are better for understanding
all of the effects on a given object and for
procedural design.
Object Oriented Analysis and Design
79
Diagrams - Statechart diagram
 A statechart diagram shows a state machine,
consisting of states, transitions, events, and
activities.
 Statechart diagrams emphasize the event-ordered
behavior of an object, which is especially useful
in modeling reactive systems.
shutDown
keyPress
Idle
Running
Finished
Object Oriented Analysis and Design
80
Statechart diagram -Example
add student / numStudents = numStudents + 1
/ numStudents = 0
remove student / numStudents = numStudents - 1
Unassigned
closeRegistration
addProfessor
cancel
Cancelled
do: Send cancellation notices
close
removeProfessor
[ numStudents = 10 ]
cancel
cancel
Full
close[ numStudents < 3 ]
add student /
numStudents = numStudents + 1
Assigned
[ numStudents = 10 ]
close
closeRegistration [ has Professor assigned ]
closeRegistration[ numStudents >= 3 ]
Committed
do: Generate class roster
close[ numStudents >= 3 ]
remove student / numStudents = numStudents - 1
Object Oriented Analysis and Design
81
Statechart diagram -Example
superstate
/ numStudents = 0
Open
Closed
closeRegistration
Cancelled
do: Send cancellation notices
close
Unassigned
cancel
cancel
substate
close[ numStudents < 3 ]
Full
remove a professor
[ numStudents = 10 ]
add a professor
close
closeRegistration [ has Professor assigned ]
Assigned
closeRegistration[ numStudents >= 3 ]
add student /
numStudents = numStudents + 1
H
close[ numStudents >= 3 ]
remove student / numStudents = numStudents - 1
Object Oriented Analysis and Design
82
Committed
do: Generate class roster
Diagrams - Activity Diagram
 An activity diagram shows the flow from activity to activity within a
system.
initial state
Select site
action state
Bid Plan
[ not accepted ]
[ else ]
decisio
n
Do site work
guard
expression
concurrent fork
Do trade work
concurrent join
Finish construction
final state
Object Oriented Analysis and Design
83
Extension mechanism of the UML
Object Oriented Analysis and Design
84
Extension mechanism of the UML
 Stereotype
 Tagged value
 Constraint
Object Oriented Analysis and Design
85
Extension mechanism - Stereotypes
 A stereotype is an extension of the vocabulary of the UML,
allowing you to create new kinds of building blocks
similar to existing ones but specific to your problem.
 Stereotypes must be based on certain existing types or
classes in the metamodel. Stereotypes may extend the
semantics, but not the structure of pre-existing types and
classes. Certain stereotypes are predefined in the UML,
others may be user defined.
<<boundary>>
LoginForm
LoginForm
Stereotyped element as icon
Named Stereotype
Object Oriented Analysis and Design
86
Stereotypes
 Stereotypes define a new model element in
terms of another model element.
 Sometimes, you need to introduce new
things that speak the language of your
domain and look like primitive building
blocks.
 Represented with name in guillemets or as
a different icon
<<Interface>>
Shape
Shape
Object Oriented Analysis and Design
87
Extension mechanism - Tagged Values
 Many kinds of elements have detailed properties that do
not have a visual notation. In addition, users can define
new element properties using the tagged value
mechanism.
 A tagged value is an extension of the properties of a
UML element, allowing you to create new information in
that element’s specification.
 A tagged value is a keyword-value pair that may be
attached to any kind of model element The keyword is
called a tag.
Object Oriented Analysis and Design
88
Tagged Values - Example
Common examples of tagged values are:
•
{Author = (Dave,Ron)}
•
{Version Number = 3}
•
{Location = d:\java\uml\examples}
•
{Location = Node: Middle Tier}
MyClass
{Version =
1.02}
Object Oriented Analysis and Design
89
Extension mechanism - Constraint
 A constraint is an extension of the semantics of a UML
elements, allowing you to add new rules or to modify
existing ones.
 Constraints may be written as free-form text. If you want to
specify your semantics more precisely, you can use the
UML’s Objec Constraint Language(OCL).
Simple constraint Portfolio
{secure}
BankAccount
Corporation
{or}
Person
gender : {female,male}
Constraint across multiple elements
+husband
Formal constraint using OCL
+wife
0..1
0..1
{self.wife.gender = female and self.husband.gender = male}
Object Oriented Analysis and Design
90
Common Modeling Techniques
1) Modeling Comments - use notes
2) Modeling New Building Blocks - use stereotype.
3) Modeling New Properties - use tagged values.
4) Modeling New Semantics - use constraint
Object Oriented Analysis and Design
91
Simple Example – Hello World
Object Oriented Analysis and Design
92
Simple Example - Hello World
 Key Abstractions
 Mechanisms
 Components
Object Oriented Analysis and Design
93
Example - Key Abstractions
import java.awt.Graphics;
class HelloWorld extends java.applet.Applet
{
public void paint (Graphics g) {
g.drawString (“Hello World !”,10,10);
}
}
Applet
HelloWorld
paint()
Graphics
g.drawString (“Hello World !”,10,10)
Object Oriented Analysis and Design
94
HelloWorld
paint()
Example - Key Abstractions
Object
Component
ImageObserver
Container
jav
a
HelloWorld
applet
Panel
awt
lang
Applet
HelloWorld
Object Oriented Analysis and Design
95
Example - Mechanisms
client
: Thread
run( )
: Toolkit
:
ComponentPeer
target :
HelloWord
run( )
callbackLoop( )
handleExpose( )
painting机制
Object Oriented Analysis and Design
96
paint( )
Example - Components
HelloWorld.class
hello.html
hello.jpg
HelloWorld Component
Object Oriented Analysis and Design
97
hello.java
Descargar

Document