Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 28

UML Class Diagrams

UNIT II - STATIC UML DIAGRAMS


Class Diagram–– Elaboration – Domain Model – Finding
conceptual classes and description classes – Associations
– Attributes – Domain model refinement – Finding
conceptual class Hierarchies – Aggregation and
Composition - Relationship between sequence diagrams
and use cases – When to use Class Diagrams
Basic concepts

Design Class Diagram


In a conceptual perspective the class diagram can be used
to visualize a domain model.
A common modeling term for this purpose is design class
diagram (DCD).
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
Attribute Text and Association Lines

Attributes of a classifier (also called structural properties in


the UML) are shown several ways:

 attribute text notation, such as currentSale : Sale.

 association line notation

 both together
Attribute Text and Association Lines
The full format of the attribute text notation is:

visibility name : type multiplicity = default {property-string}

visibility marks include + (public), - (private), and so


forth.
When to Use Attribute Text versus Association
Lines for Attributes?
Use the attribute text notation for data type
objects and the association line notation for
others.
Common data types are primitive-oriented types
such as:

 Boolean, Date (or DateTime), Number,


Character, String (Text), Time, Address, Color,
Geometrics (Point, Rectangle), Phone Number,
Social Security Number, Universal Product Code
(UPC), SKU, ZIP or postal codes, enumerated
types
The UML Notation for an Association End

 The end of an association can have a navigability arrow.


It can also include an optional role name to indicate the
attribute name. And of course, the association end may
also show a multiplicity value, such as '*' or '0..1'.

 A property string such as {ordered} or {ordered, List} is


possible. {ordered} is a UML-defined keyword that implies
the elements of the collection are ordered. Another related
keyword is {unique}, implying a set of unique elements.
How to Show Collection Attributes with
Attribute Text and Association Lines?
public class Sale
{
private List<SalesLineItem> lineItems = new
ArrayList<SalesLineItem>();
// …}
Operations and Methods
One of the compartments of the UML class box shows the
signatures of operations. At the time of this writing, the full,
official format of the operation syntax is:

visibility name (parameter-list) {property-string}


visibility name (parameter-list) : return-type {property-
string}

The property string contains arbitrary additional


information, such as exceptions that may be raised, if
the operation is abstract, and so forth.
 For example, both expressions are possible:
+ getPlayer( name : String ) : Player {exception
IOException}
public Player getPlayer( String name ) throws IOException
How to Show Methods in Class Diagrams?
A UML method is the implementation of an operation; if
constraints are defined, the method must satisfy them.

Operation Issues in DCDs
1. The create Operation

In a DCD this create message will usually be mapped to a


constructor definition, using the rules of the language
such as the constructor name equal to the class name
(Java, C#, C++,…).
2. Operations to Access Attributes

 Accessing operations retrieve or set attributes, such as


getPrice and setPrice.
KEYWORDS
Generalization, Abstract Classes, Abstract Operations
Generalization:

 Generalization in the UML is shown with a solid line and fat


triangular arrow from the subclass to superclass.

Thus, the specific classifier indirectly has features of the more


general classifier.

Abstract classes and operations

Abstract classes and operations can be shown either with an


{abstract} tag (useful when sketching UML) or by italicizing
the name (easy to support in a UML tool).

 The opposite case, final classes and operations that can't be


overridden in subclasses, are shown with the {leaf} tag.
Dependency

 The UML includes a general dependency relationship that


indicates that a client element (of any kind, including
classes, packages, use cases, and so on) has knowledge of
another supplier element and that a change in the supplier
could affect the client.

 Dependency is illustrated with a dashed arrow line from


the client to supplier.


Interfaces

The UML provides several ways to show interface


implementation, providing an interface to clients, and
interface dependency. In the UML, interface
implementation is formally called interface realization.

Interfaces
Constraints
A UML constraint is a restriction or condition on a UML
element.
It is visualized in text between braces; for example: { size
>= 0 }. The text may be natural language or anything else,
such as UML's formal specification language, the Object
Constraint Language (OCL)
Qualified Association
A qualified association has a qualifier that is used to
select an object (or objects) from a larger set of related
objects, based upon the qualifier key.
For example, if a ProductCatalog contains many
ProductDescriptions, and each one can be selected by an
itemID.
Singleton Classes
Template Classes and Interfaces
Commonly used for the element type of collection classes,
such as the elements of lists and maps.

public class Board


{
private List<Square> squares = new ArrayList<Square>();
// …
}
the List interface and the ArrayList class (that implements
the List interface) are parameterized with the element type
Square.
User-Defined Compartments
In addition to common predefined compartments class
compartments such as name, attributes, and operations,
user-defined compartments can be added to a class box.
Active Class
An active object runs on and controls its own thread of
execution. Not surprisingly, the class of an active
object is an active class.
What's the Relationship Between
Interaction and Class Diagrams?
What's the Relationship Between
Interaction and Class Diagrams?
From interaction diagrams the definitions of class
diagrams can be generated.
This suggests a linear ordering of drawing
interaction diagrams before class diagrams, but in
practice, especially when following the agile
modeling practice of models in parallel, these
complementary dynamic and static views are
drawn concurrently.

You might also like