Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
UML
UML is a language used for object-oriented analysis and
design.
UML includes a set of graphical notation techniques to create
visual models of software systems.
Three developers of UML are Grady Booch, Ivar Jacobson
and James Rumbaugh.
UML is a language for visualizing, specifying, constructing,
documenting.
UML is not a development method. It is designed to be
compatible with the object-oriented software development
methods.
UML
UML can be used to construct nine different types of
diagrams to capture five different views of a system.
Just as a building can be modeled from several views (or
perspectives) such as ventilation perspective, electrical
perspective, lighting perspective, heating perspective, etc.;
the different UML diagrams provide different perspectives
of the software system to be developed and facilitate a
comprehensive understanding of the system.
Such models can be refined to get the actual
implementation of the system.
UML
Views in UML
1. Functional View:
This view describes functional requirements of the system.
Use case diagrams give static functional view for functions
and static relationships.
Activity diagrams give dynamic functional view.
Views in UML
3. Behavioral (dynamic structural) view:
Interaction diagrams- collaboration diagrams and sequence
diagrams describe sequences of interactions between objects.
State transition diagrams show state-based behavior of
objects.
4. Architectural View:
This view describes logical and physical structure.
Component diagrams and deployment diagrams are used in
this view.
Views in UML
classes
Attributes
operations (or methods),
Relationships among the classes.
Essential Elements of a
UML Class Diagram
Class
Attributes
Operations
Relationships
Associations
Generalization
Realization
Dependency
Class
Describes a set of objects having similar:
Attributes (status)
Operations (behavior)
Relationships with other classes
Class
Name
Window
Attributes
size: Size
visibility: boolean
Operations
display()
hide()
Associations
An association between two classes indicates that
objects at one end of an association recognize
objects at the other end and may send messages to
them.
Example: An Employee works for a Company
Employee
Company
Associations (cont.)
Role
name
StaffMember
instructor
1..*
Multiplicity
Association
name
instructs
Navigable
(uni-directional)
association
Student
Role
*
Courses
Reflexive
association
pre requisites
0..3
Associations (cont.)
To clarify its meaning, an association may be named.
The name is represented as a label placed midway along
the association line.
Usually a verb or a verb phrase.
Associations (cont.)
Multiplicity
the number of objects that participate in the association.
Indicates whether or not an association is mandatory.
Multiplicity Indicators
Exactly one
Zero or more (unlimited)
1
* (0..*)
One or more
1..*
0..1
Specified range
2..4
2, 4..6, 8
Aggregation
A special form of association that models a
whole-part relationship between an
aggregate (the whole) and its parts.
Models a is a part-part of relationship.
2..*
Car
Whole
Door
Part
1..*
House
Aggregation (cont.)
Aggregation tests:
Is the phrase part of used to describe the relationship?
A door is part of a car
Composition
A strong form of aggregation
The whole is the sole owner of its part.
The part object may belong to only one whole
Circle
Polygon
Point
3..*
Circle
Point
Generalization
An abstract
class
Shape
{abstract}
Generalization
relationship
Circle
Super
Class
Sub
Class
Generalization
A sub-class inherits from its super-class
Attributes
Operations
Relationships
A sub-class may
Add attributes and operations
Add relationships
Refine (override) inherited operations
Realization
A realization relationship indicates that one
class implements a behavior specified by
another class (an interface or protocol).
An interface can be realized by many
classes.
A class may realize many interfaces.
LinkedList
<<interface>>
List
ArrayList
Dependency
Dependency is a weaker form of relationship which
indicates that one class depends on another because it uses
it at some point in time.
One class depends on another if the independent class is a
parameter variable or local variable of a method of the
dependent class.
This is different from an association, where an attribute of
the dependent class is an instance of the independent class.
Iterator
<<friend>>
Vector
*
{ total < $50 }
Constraint
Order
may be
canceled
Note
focus
auxiliary
type
utility
focus
Focus is class that defines the core logic or control flow
for one or more supporting classes.
The supporting classes may be defined either explicitly
using auxiliary classes or implicitly by dependency
relationships.
Focus classes are typically used for specifying the core
business logic or control flow of components during
design phase.
auxiliary
Auxiliary is class that supports another more central or
fundamental class, typically by implementing
secondary logic or control flow.
The class that the auxiliary supports may be defined
either explicitly using a focus class or implicitly by a
dependency relationship.
Auxiliary classes are typically used for specifying the
secondary business logic or control flow of components
during design phase.
type
Type is class that specifies a domain of objects together
with the operations applicable to the objects, without
defining the physical implementation of those objects.
Type may have attributes and associations.
Behavioral specifications for type operations may be
expressed using, for example, activity diagrams.
An object may have at most one implementation class,
however it may conform to multiple different types.
utility
Utility is class that has only class
scoped static attributes and
operations.
As such, utility class usually has
no instances.
Math is utility class - having
static attributes and operations
(underlined)
E
X
A
M
P
L
E
Fill in Multiplicity
Determine the number of occurrences of one class for a
single occurrence of the associated class.
Identify Behaviors Specify the operations that are required for each class.
(assume getter and setter methods for each attribute.)
Identify Classes
These are the abstract or physical things in our system
which we wish to describe.
Find all the nouns and noun phrases in the domain
descriptions you have obtained through your analysis.
Consider these class candidates.
The class candidates are departments, chair, professor,
course, and course section.
Since there is only one instance of the University, we
exclude it from our consideration.
Find Associations
Now find the verbs that join the nouns. e.g., The
professor (noun) teaches (verb) students (noun).
The verb in this case, defines an association between
the two nouns.
Identify the type of association.
Use a matrix to define the associations between classes.
Fill in Multiplicity
Determine the number of occurrences of one class for a
single occurrence of the associated class.
Identify Attributes
Name the information
details (fields) which are
relevant
to
the
application domain for
each class. Add these
attributes.
We have the department name, the professor name,
the professor employee id, the course names, the
course schedule, the term/year that the course is
taught, the departments the professor is assigned to,
the department that offers the course.
Identify Behaviors
Specify the operations that are
required for each class.
(assume getter and setter methods
for each attribute.)
In this example - we are not given
any behaviors, so we will have to
make them up.
What are some behaviors of these
classes?
41
School
has
1..*
Department
Department
1
offers
1..*
Subject
42
Instructor
1..*
assigned to
1..*
Department
Student
*
takes
0..5
Subject
43
Instructor
1..*
teaches
1..3
Subjects
44
Student
*
member
1..*
School
45
School
Department
1..*
1..*
1*
offeres
assignedTo
member
Student
1..*
1..*
attends
*
Subject
1..5
teaches
Instructor
1..3 1..*
46
Employee
1..*
Assigned To
Project
+name : string
Artifact
1
0..*
+name : string
+name : string
+status : enum
1
1
Responsible For
0..n
Manager
About
Developer
Problem Report
0..n
1
1
0..*
Managed By
History Log
0..n
History Entry
-when : Date
-whatDone : string
Lab Assignments
Class Diagram
TrafficPoliceman 1 issues *
TrafficReport
id : long
description : String
occuredAt : Date
reports of
1..*
Policeman
id : long
name : String
rank : int
<<abstract>>
Violation
id : long
description : String
Offender
1..*
name : String
id : long
Association
a relationship between instances of the two classes. There is an
association between two classes if an instance of one class must
know about the other in order to perform its work.
In a diagram, an association is a link connecting two classes.
Aggregation
an association in which one class belongs to a collection.
An aggregation has a diamond end pointing to the part containing the
whole.
In our diagram, Order has a collection of OrderDetails.
Generalization
an inheritance link indicating one class is a superclass of the
other.
A generalization has a triangle pointing to the superclass.
Payment is a superclass of Cash, Check, and Credit.
The arrow also lets you know who "owns" the association's
implementation; in this case, OrderDetail has an Item.
Associations with no navigability arrows are bidirectional.
ORDER
order no.
status
customer id
date
accept order()
edit order()
re order()
PRODUCT
product id
Order id
name
description
customer id
getCustomer()
CUSTOMER
customer id
Name
address
phone No.
QUOTATION
product id
quote no
price
date
Quantity
addCustomer()
save()
delete()
edit()
save()
delete()
SALES
STAFF
staff id
name
position
address
dept
addStaff()
delete()
save()
INVOICE
product id
invoice no
quantity
customer id
amount
vat
edit()
print()
save()
delete()
update ledger()
Class Diagram
Using
Java
Car.java
Unidirectional Association
Bidirectional Association
In the bidirectional association each of the class in this relationship refers to each other by calling each others method.
In the above Java example it is depicted as instance variable of Car class in called inside the Customer class and vice
versa.
In the above example the car and owner refers to the roles and is depicted by the name of instance variable in the
code.
Multiplicity in association
Multiplicity in association
Multiplicity in association
Generalization
Realization
This is related to the relationship
between the class and the interface.
The realization is equivalent to the
implements keyword in Java.
This is very straight forward
implementation so hopefully there
will ne no code provided.
Unlike Generalization in this case
the arrow is dashed.
Dependency
Dependency
Aggregation
Aggregation
Composition
This is again a whole or part relationship where if the whole
is destroyed then the part cannot exist independently.
Another important point about Composition is that the part
at any point in time can have only one owner.
E.g. A person can be an employee of one company at any
point in time due to contractual obligations. That person
cannot hold dual work authorization. If the Company goes
bankrupt the employee of this company does not exist and
will be fired.
Composition
The composition is
represented as a filled
diamond
with
data
flowing
in
single
direction from the whole
to the part.
The composition in Java
is represented in the
same
form
as
aggregation with help of
instance variables.