Visual Modeling Techniques

Download Report

Transcript Visual Modeling Techniques

Introduction
to UML
Part 2
Itntroduction to UML 1
Building blocks of the UML
• As part of a model you have:
– 1 modeling elements
– 2 relationships between the modeling elements
– 3 diagrams that group and visualize the modeling elements
and the relations between them.
• E.g. class diagram:
Company
1
1..*
Department
LocatedAt
*
*
1..*
Office
Itntroduction to UML 2
1 Modeling elements
• You have modeling elements for:
–
–
–
–
1.1 Structural things
1.2 Behavioral things
1.3 Grouping things
1.4 Annotational things
Itntroduction to UML 3
1.1 Structural elements
• Identified with nouns, e.g. Person; Typically
representing static parts of the model. In UML you
will find 7 different types of structual elements:
– 1.1.1 Class
– 1.1.2 Interface
– 1.1.3 Active class
– 1.1.4 Colloboration
– 1.1.5 Component
– 1.1.6 Node
– 1.1.7 Use Case
Itntroduction to UML 4
1.1.1 Class:
Describes a Set of Objects
class name
visibility
operation
signature
Point
- x : int
- y : int
+ getX() : int
+ setX(aX : int) : void
+ getY() : int
+ setY(aY : int) : void
attributes
operations
Rational Rose 2000
Rose: The icons
,
and
used instead of +, # and -
can be
Itntroduction to UML 5
Encapsulation Also Called Data Hiding
• Encapsulation: hiding the the implementation of the data
from users of the object. Users are typically objects of other
classes.
The users don’t see if the data is stored in fields, calculated or
if they are retrieved from a database, they only call a method.
• Encapsulation is achieve by never letting objects directly
access fields. Fields should only be accessed through the
object’s methods.
• Making the fields private (or protected) ensures
encapsulation. If you want objects of different types to access
the fields, then make public methods (or package
accessibility) for this purpose.
Itntroduction to UML 6
Operation Versus Method
(C++ member function)
A method is an implementation of an operation.
A method specifies the algorithm or procedure
that produces the results of an operation.
Itntroduction to UML 7
1.1.2 Interface:
A Named Set of Operations
That Describes Some Behavior
(No Implementation)
interface name
stereotype
operation
compartment
ISortable
interface - iconic form
interface - expanded form
Itntroduction to UML 8
An Interface Can Be Seen As a Protocol
• An interface is an agreement on behavior.
• A class which implements an interface agrees on
supporting the specified behavior.
• An interface can also be seen as a definition of a
role, classes which implements the role are able to
play that role.
Example: The auto-pilot of an airplane can act as a pilot the
same is true about some humans. The auto-pilot and the
human is quit different types of objects, but they can both
play the same role. Many different types of objects can
implement the interface, so the interface is not the same as
a “class to subclass from”.
Interface,
HiA by J.P.Nytun
2
Itntroduction
to UML
9
1.1.3 Active Class
Snake
pos:Point
move()
bite()
Active class: describes objects
that owns their own thread;
The behavior of this objects
can be concurrent with others
Itntroduction to UML 10
1.1.4 Colloboration
Listener
Colloboration: describes a colloboration
between roles to achieve a particular goal.
A collaboration can represent an
implementation of a use case or a particular
pattern.
Itntroduction to UML 11
1.1.5 Component
calculate.class
Component: a physical
part of the system which
implements a set of interfaces.
Itntroduction to UML 12
Different types of Components (in UML)
• Deployment Components: this components can be
assembled to form a complete executable system.
Example: A complete executable application, a dynamic
library (DLL), a JavaBean, a COM+ object.
• Work Product Components: this components are the
basis for making the deployment components. They are
not a part of the executable system, but results from the
development process. Example: Source code.
• Execution Components: this components are created by
an executing system. Example: a JavaBean created during
runtime.
Itntroduction to UML 13
Web Example
Working product
component
Deployment component
Menu.html
Menu
------------Menu.java
Could be an execution component,
e.g. Produced by a servelet
Deployment component
Menu.jpg
Itntroduction to UML 14
1.1.6 Node
videoServer
Node: a physical element that
represent a computational resource
(e.g. processor and memory).
Itntroduction to UML 15
1.1.7 Use Case
Register
for exam
Use case: describes a sequence of actions
that yields an observable result for an
actor. With use cases you can structure
the behavioral things in a model.
Itntroduction to UML 16
Extensibility Mechanisms
«container»
EventQueue
tagged value
{version 2.1}
stereotype
add(e:event)
remove(n:int)
{add runs in O(1) time}
«query»
length():int
constraint
«helper function»
reorder()
Itntroduction to UML 17
1.2 Behavioral Elements
• Describing the dynamically parts of the
model. Behavioral elements are identified
with the help of verbs.
– 1.2.1 Interaction
– 1.2.2 State
Itntroduction to UML 18
1.2.1 Interaction
User
Oven-control -unit
Oven-light
Set temperature(250C)
Heat on
light on
Interaction: A behavior that comprises a
set of messages sent between a set of objects
to archive a special purpose, like in a sequence
diagram.
Itntroduction to UML 19
1.2.2 State Machine
One State
SomeEvent / SomeAction()
An Other
State
State machine: A description of the different
states an object can go through in response to
events. Events generated by the object is also
shown. An activity diagram is a special case of
a state diagram.
Itntroduction to UML 20
1.3 Grouping Elements
• You can group elements with the help of packages.
• [1]: ”A package may own other elements, including
classes, ..., diagrams, and even other packages.”
• You can use packages to orginaze your classes
(interfaces,..) and your diagrams.
java
applet
+Applet
Itntroduction to UML 21
1.4 Annotational Elements
• You can add comments to a diagram with
the help of notes.
A comment
Itntroduction to UML 22
2 Relations
• You have 4 different relationships:
–
–
–
–
2.1 Dependency
2.2 Association
2.3 Generalitation
2.4 Realization
Itntroduction to UML 23
2.1 Dependency:
• A relationship between to modeling
elements, indicate that a change in the
destination may effect the source.
Company
Employee
add(e : employee)
The method add has an employee as argument, so
Company-class (source) is dependent of the
Employee-class (destination).
Itntroduction to UML 24
2.2 Association:
• This relationship indicate that there is a connection
from one type of objects to another type.
An important type of association is aggregation
which indicates that one object contains objects of
a given type.
Company
1
composition or
strong aggregation
multiplicity
1..*
Department
association
name
LocatedAt
*
*
1..*
Office
ordinary association
Itntroduction to UML 25
2.3 Generalization:
• A relationship between a more general
element and a more specific one. For
example: a bird is also an animal.
Animal
Bird
A bird is a specialization
of an animal.
Itntroduction to UML 26
2.4 Realization:
• UML: ”A semantic relationships between
classifiers, in which one classifiers specifies
a contract that another classifier guarantees
to carry out”.
”interface”
Movable
move(x,y)
The class Snake implements
the interface Movable.
Snake
move(x,y)
Itntroduction to UML 27
3 Diagrams
• A diagram is typically a view of a part of the
model, showing modeling elements and some of
the relationships between them.
• A diagram do not have to be complete, some
elements may be missing or presented in a
simplified fashion.
• UML: ”A well-formed model is one that is
semantically self-consistent and in harmony with
all related models.”
Itntroduction to UML 28
There are 9 types of diagrams in UML
Dynamic views
Sequence
Diagrams
Collaboration
Diagrams
Activity
Diagrams
Statechart
Diagrams
Static views
Use Case
Diagrams
Some part of
the model might
not be visible on
any diagram
Class
Diagrams
Object
Diagrams
Model
Component
Diagrams
Deployment
Diagrams
Itntroduction to UML 29
3.1 Use case diagram
actor
register a person
edit a registration/
delete a registration
User
association
use case
”include”
navigate/view
the register
include relationship
”include”
view next
person
”include”
view previous
person
system boundary
Itntroduction to UML 30
Use Case Diagram - One More Example
”A use case is a specific way of using
the system by performing some
part of the functionality.
Each use case constitutes a complete
course of events initiated by an actor,
and it specifies the interaction that
takes place between an actor and
the system....”
I. Jacobson
Register as student
Person
<<become>>
Student
Register for course
Adm
<<become>>
Register for exam
CourseParticipant
Working with course
Instructor
Make/edit course
Lecturer
Itntroduction to UML 31
3.2 Class Diagram
Person
name
: String
email
: String
homePage : String
1
responsible for
1 tech. responsible for
*
Course
: String
* name
description : String
CourseModule
*
1..* name
: String
description : String
1
1
Student
1
*
* StudentCourseProfile *
finished : boolean
When a student register for
course a StudentCourseProfile object
will be made!
Itntroduction to UML 32
A Class Diagram
With Navigation
1
Person
responsible for
name
: String 1 tech. responsible for
imail
: String
homePage : String
*
Course
: String
* name
description : String
CourseModule
: String
* 1..* name
description : String
1
1
*
Student
1
* StudentCourseProfile *
finished : boolean
Itntroduction to UML 33
A Class Diagram - Mapping to Java
1
Person
responsible for
name
: String 1 tech. responsible for
imail
: String
homePage : String
*
Course
: String
* name
description : String
1
*
Student
* StudentCourseProfile
1
finished : boolean
public class Person {
protected String name;
protected String imail;
protected String homePage;
//
// Navigation
protected Course[] responsibleFor;
protected Course[] techResponsibleFor;
public Person() {
}
}
public class Student extends Person {
//
// Navigation
public StudentCourseProfile[]
studentCourseProfile;
public Student() {
}
}
Itntroduction to UML 34
A Class Diagram - Example With Interface
<<Interface>>
IStorable
Register
-reg
0..*
relization
public void read(){
terminal.print("Name: ");
name = terminal.readLine();
...
}
edit()
write()
read()
Person
edit()
write()
read()
relization/implements
To different representation
of nearly the same
dependency
Itntroduction to UML 35
A Class Diagram One More Example With Interface
Itntroduction to UML 36
3.3 Object Diagram Capture Instances and Links
Class
Object
Company
noOfEmploees : int
HiA: Company
noOfEmploees=600
Possible object
name
object class
attribute
with value
Itntroduction to UML 37
Object Diagram with Links
Class Diagram
Company
Object Diagram
Language:
:LocatedAt
Department
Gimlemoen:
Office
1
1..*
LocatedAt
Department
Office
*
1..*
HiA: Company
Possible
object diagram
Engineering :
Department
:LocatedAt
Grooseveien:
Office
Link - A link is an instance of an association,
analogous to an object being an instance of a class.
Itntroduction to UML 38
Object diagram and Rational Rose 2000
Rational Rose 2000 does not have object diagrams,
but you can achieve much the same with a collobartion diagram
noOfEmploees = 600
HiA:Comany
Gimlemoen:Office
You can not specify attributes inside object;
One solution to this short-coming is to use a comment!
Itntroduction to UML 39
3.4 Sequence diagram
user
controllerViewer
register
<command r>
<name,e-mail,..>
”create”
person
setData(name, ..)
insert(person)
Itntroduction to UML 40
3.5 Colloboration diagram
1.2: ”create”
1.3: setDate(data)
1: register()
user
controllerViewer
person
1.1: data := getData()
1.4: insert(person)
register
Itntroduction to UML 41
3.6 Statechart diagram
Waiting
do/ display("Off")
exit/ display("Time?")
StateChart for microwave
oven "control unit"
Power turned on
Set time
do/ get number
exit/ ^timer.setTime(timeRead)
[ Door closed ]
[ Door open ]
Disabled
Door closed
do/ display("Close Door")
Door open
Operating
do/ display ("time left")
exit/ ^heattingElement.powerOff()
entry/ ^heatingElement.powerOn()
Time out
Simple microwave oven:
- Power can be on or off
- Time can be set after the power has been turned on
End
Itntroduction to UML 42
Statechart for Applet
Not
Loaded
init/init()
Running
Loaded start
stop/
stop()
/start()
destroy/destroy()
start/start()
Stopped
Itntroduction to UML 43
3.7 Activity diagram Capture Dynamic Behaviour (Activity-oriented)
Itntroduction to UML 44
Activity diagram One More Example
activity
product of activity
Itntroduction to UML 45
Activity diagram - One More Example
user
controller
person
register
request registration
create person (object)
supply person-data
forward person-data
process person-data
insert person
Itntroduction to UML 46
3.8 Component diagram Captures the Physical Structure of the Implementation
Demo.html
applet1.class
applet1.java
applet2.class
applet2.java
logo.gif
Itntroduction to UML 47
Component diagram One More Example
Person.class
Register.class
ISortable
Itntroduction to UML 48
3.9 Deployment diagram
Extended
VLAN
”Server”
”network” LAN
”PC”
”PC”
Itntroduction to UML 49
Multi-tier
Architecture
client:
browser:
Internet
- MVC -
server1:
view:
browser/jsp/servlet
controller:
jsp/servlet
model:
businessObjects
:WebServer
:html
:html
:ServletContainer
s1:Servlet
s2:Servlet
b1:BusinessObject
j1:Jsp
j2:Jsp
Intranet
b3:BusinessObject
b2:BusinessObject
b4:BusinessObject
server2:
:DB
Itntroduction to UML 50
References
•
[1] Grady Booch, James Rumbaugh and Ivar Jacobson:
The Unified Modeling Language User Guide.
Addison-Wesley, 1999
•
James Rumbaugh, Michael Blaha, William Premerlani, Frederick Eddy
and William Lorenzen:
Object-Oriented Modeling and Design.
Prentice Hall, 1991
•
Martin Fowler with Kendall Scott:
UML Distilled.
Addison-Wesley, 1997
•
Terry Quatrani:
Visual Modeling with Rational Rose and UML.
Addison-Wesley, 1998
•
Ari Jaaksi:
A Method for Your First Object-Oriented Project.
JOOP - The Journal of Object-Oriented Programming, Januar 1998
•
Rational software:
http://www.rational.com/uml/documentation.html
Itntroduction to UML 51