UML Class Diagrams
-
Upload
jelani-holloway -
Category
Documents
-
view
74 -
download
2
description
Transcript of UML Class Diagrams
![Page 1: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/1.jpg)
UML Class Diagrams
Chapter 16Applying UML and Patterns
Craig Larman
![Page 2: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/2.jpg)
Objective Create design class diagrams (DCDs). Identify the classes, methods, and
associations to show in a DCD.
![Page 3: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/3.jpg)
Class Diagrams The UML has notation for showing design
details in static structure. Class diagrams
The definition of Design Class Diagrams (DCDs) occurs within the design phase. The UML does not specifically define design
class diagram. It is a design view of software entities, rather
than an analytical view of domain concepts.
![Page 4: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/4.jpg)
Figure 16-1 DCD Summary
![Page 5: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/5.jpg)
Design Class DiagramsThe creation of design class diagrams is
dependent upon the prior creation of: Interaction diagrams
Identifies the software classes that participate in the solution, plus the methods of classes.
In practice, typically created in parallel w/ DCD Conceptual model
Adds detail to the class definitions.
![Page 6: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/6.jpg)
Example of a DCD
![Page 7: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/7.jpg)
Information in a DCD
A DCD illustrates the specifications for software classes and interfaces
Typical information included: Classes, associations, and attributes Interfaces, with their operations and constants Methods Attribute type information Navigability Dependencies
![Page 8: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/8.jpg)
Creating DCDs1. Identify all the classes participating in the
software solution by analyzing interaction diagrams
2. Draw them in a class diagram. 3. Duplicate the attributes from the associated
concepts in the conceptual model 4. Add method names by analyzing the
interaction diagrams5. Add type information to the attributes and
method parameters
![Page 9: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/9.jpg)
Creating DCDs Continued6. Add the associations necessary to support
the required attribute visibility. 7. Add navigability arrows to the associations
to indicate the direction of attribute visibility. 8. Add dependency relationship lines to
indicate non-attribute visibility.
![Page 10: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/10.jpg)
Domain model Vs. DCD
![Page 11: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/11.jpg)
Add method name Method names come from interaction diagrams
![Page 12: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/12.jpg)
After Methods Have Been Added
![Page 13: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/13.jpg)
Issues Related to Method Names The following special issues must be
considered with respect to method names: Interpretation of the create() message. Depiction of accessing methods. Interpretation of messages to multi-objects. Language-dependent syntax.
![Page 14: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/14.jpg)
Method names: “create” issue The create message is the UML language
independent form to indicate instantiation and initialization. Equivalent to calling the constructor method of
a class When translating the design to an OOPL it
must be expressed in terms of its idioms for instantiation and initialization.
![Page 15: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/15.jpg)
Method names: Accessing methods Accessing methods are those which retrieve
attribute values (accessor method - get) or set attribute values (mutator method)
It is common idiom to have an accessor and mutator for each attribute, and to declare all attributes private (to enforce encapsulation).
![Page 16: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/16.jpg)
Method names: Multi-objects A message to a multi-object is interpreted as
a message to the container/collection object.
![Page 17: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/17.jpg)
Message to a Multi-objects Java’s map, C++’s map, Smalltalk’s
dictionary.
![Page 18: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/18.jpg)
Method names:Language dependent syntax The basic UML format for methods:
methodName(parameterList)
![Page 19: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/19.jpg)
Consider the Audience for DCDs The design class diagram should be created
by considering the audience. If it is being created in a CASE tool with
automatic code generation, full and exhaustive details are necessary
If it is being created for software developers to read, exhaustive low-level detail may add too much noise
![Page 20: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/20.jpg)
DCD – examples of classes
![Page 21: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/21.jpg)
Adding Associations and Navigability Navigability is a property of the role which
indicates that it is possible to navigate uni-directionally across the association from
objects of the source to target class Navigability implies visibility Most, if not all, associations in design-
oriented class diagrams should be adorned with the necessary navigability arrows.
![Page 22: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/22.jpg)
Showing Navigability or Attribute Visibility
![Page 23: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/23.jpg)
Associations with navigability Define an association with a navigability
adornment from A to B if: A sends a message to B A creates an instance B A needs to maintain a connection to B
![Page 24: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/24.jpg)
Associations with Navigability
![Page 25: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/25.jpg)
Adding Dependency Relationships Dependency relationship indicates that one
element (of any kind, including classes, use cases, and so on) has knowledge of another element. A dependency is a using relationship that
states a change in specification of one thing may affect another thing that uses it, but not necessarily the reverse.
![Page 26: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/26.jpg)
Dependency continued
The dependency relationship is useful to depict non-attribute visibility between classes. Parameters Global or local visibility A dashed arrow line A dashed directed line
![Page 27: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/27.jpg)
Dependency relationships non-attribute visibility
![Page 28: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/28.jpg)
Notation for member details
![Page 29: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/29.jpg)
Notation for method bodies in DCDs.
![Page 30: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/30.jpg)
Interfaces The UML has several ways to show interface
implementations. Most designers use a dependency arrow and
the «interface» stereotype.
![Page 31: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/31.jpg)
Interface Example
«interface»Timer
getTime()
Clock1
getTime( )
![Page 32: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/32.jpg)
UML Stereotypes UML uses stereotypes encapsulated in
guillemots (« and », not << and >> ) to extend many diagram symbols.
Guillemots can be found in the latin-1 symbol set in Windows Insert Symbol command)
Examples: «interface» «extends» «includes» «actor» «creates»
![Page 33: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/33.jpg)
Associations An association is a structural relationship that
specifies that objects of one thing are connected to objects of another.
Shown as a solid line
![Page 34: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/34.jpg)
Generalization A generalization is a relationship between a
general thing (called the super class or parent) and a more specific kind of that thing (called the subclass or child).
is-a-kind-of relationship. Shown as solid line with empty arrowhead
![Page 35: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/35.jpg)
Aggregation / Composition Whole/part (Has-a) relationships More concerned with Compositions
Part belongs to one composite at a time Part must always belong to a composite Composite creates/deletes its parts
Aggregation: Composition:
![Page 36: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/36.jpg)
Realization A realization is a semantic relationship
between classifiers in which one classifier specifies a contract that another classifier guarantees to carry out.
We use realization in two circumstances: In the context of interfaces. In the context of collaborations.
![Page 37: UML Class Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022052511/568130c3550346895d96e26b/html5/thumbnails/37.jpg)
UP Artifacts