UML Class Diagrams
1
What They Are
• They illustrate classes, interfaces, and their
associations. They are used for static object
modeling.
2
3
Design Class Diagram
• A class diagram can be used to visualize a
domain model. We also need a unique term to
clarify when the class diagram is used in a
software or design perspective. A common
modeling term for this purpose is design class
diagram (DCD)
4
Design Class Diagram
5
Classifier
• A UML classifier is “a model element that
describes behavioral and structure features”.
Classifiers can also be specialized. They are a
generalization of many of the elements of the
UML, including classes, interfaces, use cases,
and actors. In class diagrams, the two most
common classifiers are regular classes and
interfaces.
6
Showing UML Attributes
• Attribute text notation such as: currentSale :
Sale, Association line notation, or both
• <visibility> name : type multiplicity = default
{property string}
• Attributes are assumed private if no visibility
is given
• Arrow shows that the object where the arrow
starts has one object of the object to which it
points.
7
UML Attributes
8
UML Attributes
• Multiplicity shows how many on the left can
associate with how many on the right
• Role name
• Attributes are assumed private unless
otherwise noted
9
Attribute Text vs. Association Lines
• Use text notation for primitive data types,
even things like Zip codes that may have
components but are not complex
• Use association for everything else.
10
Collection Attributes
11
Note Symbols
• A UML note symbol is displayed as a dog-eared
rectangle with a dashed line to the annotated
element; they’ve already been used throughout
the book. A note symbol may represent several
things, such as:
– a UML note or comment, which by definition have no
semantic impact
– a UML constraint, in which case it must be encased in
braces ‘{…}’
– a method body—the implementation of a UML
operation
12
Operations and Methods
• A method is the implementation of an
operation
13
The Create operation
• This is a constructor call
• You can use <<constructor>> to make this
explicit
14
Keywords
• A UML keyword is a textual adornment to
categorize a model element
• Keywords include <<actor>>, <<Interface>>,
[abstract], [ordered]
15
Stereotypes, Profiles, Tags
• Stereotypes are also shown in guillemets
symbols . They are not keywords. A
stereotype represents a refinement to an
existing modeling concept
16
Properties and Property Strings
• A property is “a named value denoting a
characteristic of an element
• Textual approach is to use the UML property
string {name1=value1, name2=value2} format,
such as {abstract, visibility=public}
17
Generalization
• A taxonomic relationship between a more
general classifier and a more specific classifier
• This can imply inheritance, but not at the
conceptual level.
18
Dependency
• Similar to association. Indicates that a client
element has knowledge of another supplier element,
and a change in the supplier could affect the client
• (Supplier and client are descriptive terms, not
classes)
• Dependency lines are common on class and package
diagrams
• Use to depict global, parameter variable, local
variable, and static-method dependency
19
Types of Dependency
• Having an attribute of supplier type
• Send a message to a supplier
• Receiving a parameter of supplier type
• Supplier is a superclass or interface
• Indicated by a dashed line arrow
20
Interfaces
21
Composition Vs. Aggregation
• Aggregation is a vague association suggesting
whole-part relationships. No meaningful
semantics in UML versus association.
• Composition, or composite aggregation, is a
strong kind of whole-part relationship.
• Implies that an instance of the part belongs to
only one composite instance of the whole
22
Composition
• For example the Monopoly board consists of
40 squares
• A square can be part of only one board at any
time.
23
Constraints
• Constraints is a restriction on a UML element.
• Shown as text between braces
• {size > 0}
24
Qualified Association
• Uses a qualifier to select an object or set of
objects from a larger set
• For example, looking up something in a
HashMap
25
Association Class
• Allows you to treat an association as a class,
such that it can have attributes
26
Singleton Class
• Only one instance of a Singleton class (pattern
explained later) is ever instantiated.
• For example, your main class in most
programs is a Singleton, although this may not
be its dominant pattern.
27
Template Classes and Interfaces
• These are equivalent to C++ or Java
“generics.”
• That is, you can type a collection class.
28
User-Defined Compartments
• In a class diagram you can define your own
compartments:
29
DataAccessObject
Id: int
doX();
Exceptions thrown
DatabaseException
IOExeception
Responsibilities
Serialize and write objects
Read and deserialize objects
Active Class
• An active object runs on and controls its own
thread of execution
• In UML, it is shown with double vertical lines
on the left and right of the class box.
30

Class diagram

  • 1.
  • 2.
    What They Are •They illustrate classes, interfaces, and their associations. They are used for static object modeling. 2
  • 3.
  • 4.
    Design Class Diagram •A class diagram can be used to visualize a domain model. We also need a unique term to clarify when the class diagram is used in a software or design perspective. A common modeling term for this purpose is design class diagram (DCD) 4
  • 5.
  • 6.
    Classifier • A UMLclassifier is “a model element that describes behavioral and structure features”. Classifiers can also be specialized. They are a generalization of many of the elements of the UML, including classes, interfaces, use cases, and actors. In class diagrams, the two most common classifiers are regular classes and interfaces. 6
  • 7.
    Showing UML Attributes •Attribute text notation such as: currentSale : Sale, Association line notation, or both • <visibility> name : type multiplicity = default {property string} • Attributes are assumed private if no visibility is given • Arrow shows that the object where the arrow starts has one object of the object to which it points. 7
  • 8.
  • 9.
    UML Attributes • Multiplicityshows how many on the left can associate with how many on the right • Role name • Attributes are assumed private unless otherwise noted 9
  • 10.
    Attribute Text vs.Association Lines • Use text notation for primitive data types, even things like Zip codes that may have components but are not complex • Use association for everything else. 10
  • 11.
  • 12.
    Note Symbols • AUML note symbol is displayed as a dog-eared rectangle with a dashed line to the annotated element; they’ve already been used throughout the book. A note symbol may represent several things, such as: – a UML note or comment, which by definition have no semantic impact – a UML constraint, in which case it must be encased in braces ‘{…}’ – a method body—the implementation of a UML operation 12
  • 13.
    Operations and Methods •A method is the implementation of an operation 13
  • 14.
    The Create operation •This is a constructor call • You can use <<constructor>> to make this explicit 14
  • 15.
    Keywords • A UMLkeyword is a textual adornment to categorize a model element • Keywords include <<actor>>, <<Interface>>, [abstract], [ordered] 15
  • 16.
    Stereotypes, Profiles, Tags •Stereotypes are also shown in guillemets symbols . They are not keywords. A stereotype represents a refinement to an existing modeling concept 16
  • 17.
    Properties and PropertyStrings • A property is “a named value denoting a characteristic of an element • Textual approach is to use the UML property string {name1=value1, name2=value2} format, such as {abstract, visibility=public} 17
  • 18.
    Generalization • A taxonomicrelationship between a more general classifier and a more specific classifier • This can imply inheritance, but not at the conceptual level. 18
  • 19.
    Dependency • Similar toassociation. Indicates that a client element has knowledge of another supplier element, and a change in the supplier could affect the client • (Supplier and client are descriptive terms, not classes) • Dependency lines are common on class and package diagrams • Use to depict global, parameter variable, local variable, and static-method dependency 19
  • 20.
    Types of Dependency •Having an attribute of supplier type • Send a message to a supplier • Receiving a parameter of supplier type • Supplier is a superclass or interface • Indicated by a dashed line arrow 20
  • 21.
  • 22.
    Composition Vs. Aggregation •Aggregation is a vague association suggesting whole-part relationships. No meaningful semantics in UML versus association. • Composition, or composite aggregation, is a strong kind of whole-part relationship. • Implies that an instance of the part belongs to only one composite instance of the whole 22
  • 23.
    Composition • For examplethe Monopoly board consists of 40 squares • A square can be part of only one board at any time. 23
  • 24.
    Constraints • Constraints isa restriction on a UML element. • Shown as text between braces • {size > 0} 24
  • 25.
    Qualified Association • Usesa qualifier to select an object or set of objects from a larger set • For example, looking up something in a HashMap 25
  • 26.
    Association Class • Allowsyou to treat an association as a class, such that it can have attributes 26
  • 27.
    Singleton Class • Onlyone instance of a Singleton class (pattern explained later) is ever instantiated. • For example, your main class in most programs is a Singleton, although this may not be its dominant pattern. 27
  • 28.
    Template Classes andInterfaces • These are equivalent to C++ or Java “generics.” • That is, you can type a collection class. 28
  • 29.
    User-Defined Compartments • Ina class diagram you can define your own compartments: 29 DataAccessObject Id: int doX(); Exceptions thrown DatabaseException IOExeception Responsibilities Serialize and write objects Read and deserialize objects
  • 30.
    Active Class • Anactive object runs on and controls its own thread of execution • In UML, it is shown with double vertical lines on the left and right of the class box. 30