SD 05 UML1 - UHgabriel/courses/cosc3351_s08/SD_05_UML1.pdf · Microsoft PowerPoint -...
Transcript of SD 05 UML1 - UHgabriel/courses/cosc3351_s08/SD_05_UML1.pdf · Microsoft PowerPoint -...
1
Edgar Gabriel
COSC 3351
Software Design
An Introduction to UML (I)
This lecture contains material from:
www.omg.org/docs/omg/01-03-02.ppt
http://wps.prenhall.com/esm_pfleeger_softengtp_2
http://dn.codegear.com/article/31863
http://sunset.usc.edu/classes/cs577a_2000/lectures/05/EC-05.ppt
Edgar Gabriel
Spring 2008
COSC 3351 – Software Design
Edgar Gabriel
• The UML is a graphical language for
– specifying
– visualizing
– constructing
– documenting
the artifacts of software systems
• Added to the list of OMG adopted technologies in November 1997 as UML 1.1
• Define an easy-to-learn but semantically rich visual modeling language
• Include ideas from other modeling languages
• Incorporate industry best practices
• Address contemporary software development issues
– scale, distribution, concurrency, executability, etc.
• Provide flexibility for applying different processes
• Enable model interchange and define repository interfaces
UML
www.omg.org/docs/omg/01-03-02.ppt
2
COSC 3351 – Software Design
Edgar Gabriel
OMG UML Evolution
1997
(adopted by OMG)
1998
1999
Q1 2001
2001 Q4
(planned)
Editorial revision
without significant
technical changes.
2002
(planned)
<<document>>
UML 1.1
<<document>>
UML 1.2
<<document>>
UML 1.3
<<document>>
UML 1.4
<<document>>
UML 2.0
Infrastructure
<<document>>
UML 2.0
<<document>>
UML 2.0
Superstructure
<<document>>
UML 2.0 OCL
composition
(whole-part)
relationship
dependency
relationship
From [Kobryn 01a].
COSC 3351 – Software Design
Edgar Gabriel
Type of UML diagrams
• There are different types of UML diagram, each with slightly different syntax rules:– use cases.
– class diagrams.
– sequence diagrams.
– package diagrams.
– state diagrams
– activity diagrams
– deployment diagrams.
http://sunset.usc.edu/classes/cs577a_2000/lectures/05/EC-05.ppt
3
COSC 3351 – Software Design
Edgar Gabriel
Different UML diagrams
http://wps.prenhall.com/esm_pfleeger_softengtp_2
COSC 3351 – Software Design
Edgar Gabriel
UML syntax (I)
• Actors: a UML actor indicates an interface
(point of interaction) with the system.
– Actors may be people, or other systems.
– Actors used to group and name sets of system
interactions.
– An actor is NOT part of the system. An actor is
something external that your system has to deal
with.
• Boxes: boxes are used variously throughout
UML to indicate discrete elements, groupings
and containment. http://sunset.usc.edu/classes/cs577a_2000/lectures/05/EC-05.ppt
4
COSC 3351 – Software Design
Edgar Gabriel
UML syntax (II)
• Arrows: arrows usually indicate flow, dependency,
association or generalization (depending on the type of
diagram)
• Cardinality: applied to arrows, show relative numerical
relationships between elements in a model: 1 to 1, 1
to many, etc.
http://sunset.usc.edu/classes/cs577a_2000/lectures/05/EC-05.ppt
COSC 3351 – Software Design
Edgar Gabriel
UML syntax (III)
• Constraints: allow notation of arbitrary constraints on
model elements. Used, for example, to constrain the
value of a class attribute (a piece of data).
• Stereotypes: allow to extend the semantics of UML
with English. A stereotype is usually a word or short
phrase that describes what a diagram element does.
That is, we mark an element with a word that will
remind us of a common (stereotypical) role for that
sort of thing. Stereotypes should always be applied
consistently (with the same intended meaning in all
instances).
http://sunset.usc.edu/classes/cs577a_2000/lectures/05/EC-05.ppt
5
COSC 3351 – Software Design
Edgar Gabriel
UML diagrams: use cases (I)
• A use case encodes a typical user interaction with the
system. In particular, it:
– captures some user-visible function.
– achieves some concrete goal for the user.
• A complete set of use cases largely defines the
requirements for a system: everything the user can
see, and would like to do.
• The granularity of use cases determines the total
number of use cases for the system. A clear design
depends on showing the right level of detail.
• A use case maps actors to functions. The actors need
not be people.
http://sunset.usc.edu/classes/cs577a_2000/lectures/05/EC-05.ppt
COSC 3351 – Software Design
Edgar Gabriel
UML diagrams: use cases (II)
• Use case diagrams are helpful in three areas.
– determining features (requirements). New use cases
often generate new requirements as the system is
analyzed and the design takes shape.
– communicating with clients. Their notational simplicity
makes use case diagrams a good way for developers to
communicate with clients.
– generating test cases. The collection of scenarios for a
use case may suggest a suite of test cases for those
scenarios.
http://dn.codegear.com/article/31863
6
COSC 3351 – Software Design
Edgar Gabriel
Example: Relationships in a news web site
UML diagrams: use cases (III)
http://sunset.usc.edu/classes/cs577a_2000/lectures/05/EC-05.ppt
COSC 3351 – Software Design
Edgar Gabriel
UML diagrams: use cases (IV)
• The notes between << >> marks are stereotypes:
identifiers added to make the diagram more
informative. Here they differentiate between different
roles (ie, different meanings of an arrow in this
diagram).
http://sunset.usc.edu/classes/cs577a_2000/lectures/05/EC-05.ppt
7
COSC 3351 – Software Design
Edgar Gabriel
What is structural modeling?
• Structural model: a view of a system that
emphasizes the structure of the objects, including
their classifiers, relationships, attributes and
operations.
www.omg.org/docs/omg/01-03-02.ppt
COSC 3351 – Software Design
Edgar Gabriel
Construct Description Syntax
class a description of a set of objects that share the same attributes, operations, methods, relationships and semantics.
interface a named set of operations that characterize the behavior of an element.
component a modular, replaceable and significant part of a system that packages implementation and exposes a set of interfaces.
node a run-time physical object that represents a computational resource.
«interface»
Structural Modeling: Core Elements
www.omg.org/docs/omg/01-03-02.ppt
8
COSC 3351 – Software Design
Edgar Gabriel
Structural Modeling: Core Elements(cont’d)
Construct Description Syntax
constraint¹ a semantic condition or restriction.
{constraint}
¹ An extension mechanism useful for specifying structural elements.
www.omg.org/docs/omg/01-03-02.ppt
COSC 3351 – Software Design
Edgar Gabriel
Construct Description Syntax
association a relationship between two or more classifiers that involves connections among their instances.
aggregation A special form of association that specifies a whole-part relationship between the aggregate (whole) and the component part.
composition strong association in which the part can belong to only one whole
generalization a taxonomic relationship between a more general and a more specific element.
Structural Modeling: Core Relationships
www.omg.org/docs/omg/01-03-02.ppt
9
COSC 3351 – Software Design
Edgar Gabriel
Construct Description Syntax
realization a relationship between a specification and its implementation.
dependency a relationship between two modeling elements, in which a change to one modeling element (the independent element) will affect the other modeling element (the dependent element).
Structural Modeling: Core Relationships (II)
www.omg.org/docs/omg/01-03-02.ppt
Zero or more0..*
One or more1..*
Zero or one0..1
Specified range2..7
Exactly one1
Cardinality
COSC 3351 – Software Design
Edgar Gabriel
• Show the static structure of the model– the entities that exist (e.g., classes, interfaces,
components, nodes)– internal structure– relationship to other entities
• Do not show– temporal information
• Kinds– static structural diagrams
• class diagram• object diagram
– implementation diagrams• component diagram• deployment diagram
Structural Diagram Tour
www.omg.org/docs/omg/01-03-02.ppt
10
COSC 3351 – Software Design
Edgar Gabriel
Class diagrams - example
http://dn.codegear.com/article/31863
COSC 3351 – Software Design
Edgar Gabriel
Class diagrams (II)
• UML class notation is a rectangle divided into three
parts:
– class name,
– attributes, and
– operations.
• Names of abstract classes, such as Payment, are in
italics.
• Relationships between classes are the connecting links.
http://dn.codegear.com/article/31863
11
COSC 3351 – Software Design
Edgar Gabriel
Class diagrams (III)
• Our class diagram has three kinds of relationships.
– 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.
– Aggregation: an association in which one class belongs to
a collection. An aggregation has a diamond end pointing
to the part containing the whole.
– Generalization: an inheritance link indicating one class is
a superclass of the other. A generalization has a triangle
pointing to the superclass.
http://dn.codegear.com/article/31863
COSC 3351 – Software Design
Edgar Gabriel
Class diagrams (IV)
• A navigability arrow on an association shows which direction
the association can be traversed or queried. An OrderDetailcan be queried about its Item, but not the other way
around. 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 bi-
directional.
• The multiplicity of an association end is the number of
possible instances of the class associated with a single
instance of the other end. Multiplicities are single numbers
or ranges of numbers. In our example, there can be only one
Customer for each Order, but a Customer can have any
number of Orders.
http://dn.codegear.com/article/31863
12
COSC 3351 – Software Design
Edgar Gabriel
Class Diagrams (V)
• Associations in which an object is part of a whole are
aggregations. Composition is a strong association in
which the part can belong to only one whole -- the part
cannot exist without the whole. Composition is denoted
by a filled diamond at the whole end.
• This diagram shows that a BoxOffice belongs to exactly
one MovieTheater. Destroy the MovieTheater and the
BoxOffice goes away! The collection of Movies is not so
closely bound to the MovieTheater.
http://dn.codegear.com/article/31863
COSC 3351 – Software Design
Edgar Gabriel
Class information: visibility and scope
• The illustration uses the following UML™ conventions.
• Static members are underlined. Instance members are not.
• The operations follow this form:
<access specifier> <name> ( <parameter list>) : <return type>
• The parameter list shows each parameter type preceded by a
colon.
• Access specifiers appear in front of each member.
http://dn.codegear.com/article/31863