chapter 16 uml class diagrams 1cs6359 fall 2012 john cole

30
Chapter 16 UML Class Diagrams 1 CS6359 Fall 2012 John Cole

Upload: poppy-lester

Post on 06-Jan-2018

227 views

Category:

Documents


1 download

DESCRIPTION

3

TRANSCRIPT

Page 1: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Chapter 16

UML Class Diagrams

1CS6359 Fall 2012 John Cole

Page 2: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

What They Are

• They illustrate classes, interfaces, and their associations. They are used for static object modeling.

2CS6359 Fall 2012 John Cole

Page 3: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

3CS6359 Fall 2012 John Cole

Page 4: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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)

4CS6359 Fall 2012 John Cole

Page 5: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Design Class Diagram

CS6359 Fall 2012 John Cole 5

Page 6: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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.

CS6359 Fall 2012 John Cole 6

Page 7: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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.

CS6359 Fall 2012 John Cole 7

Page 8: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

UML Attributes

CS6359 Fall 2012 John Cole 8

Page 9: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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

CS6359 Fall 2012 John Cole 9

Page 10: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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.

CS6359 Fall 2012 John Cole 10

Page 11: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Collection Attributes

CS6359 Fall 2012 John Cole 11

Page 12: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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

CS6359 Fall 2012 John Cole 12

Page 13: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Operations and Methods

• A method is the implementation of an operation

CS6359 Fall 2012 John Cole 13

Page 14: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

The Create operation

• This is a constructor call• You can use <<constructor>> to make this

explicit

CS6359 Fall 2012 John Cole 14

Page 15: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Keywords

• A UML keyword is a textual adornment to categorize a model element

• Keywords include <<actor>>, <<Interface>>, [abstract], [ordered]

CS6359 Fall 2012 John Cole 15

Page 16: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Stereotypes, Profiles, Tags• Stereotypes are also shown in guillemets

symbols . They are not keywords. A stereotype represents a refinement to an existing modeling concept

CS6359 Fall 2012 John Cole 16

Page 17: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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}

CS6359 Fall 2012 John Cole 17

Page 18: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Generalization

• A taxonomic relationship between a more general classifier and a more specific classifier

• This can imply inheritance, but not at the conceptual level.

CS6359 Fall 2012 John Cole 18

Page 19: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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

CS6359 Fall 2012 John Cole 19

Page 20: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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

CS6359 Fall 2012 John Cole 20

Page 21: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Interfaces

CS6359 Fall 2012 John Cole 21

Page 22: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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

CS6359 Fall 2012 John Cole 22

Page 23: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Composition

• For example the Monopoly board consists of 40 squares

• A square can be part of only one board at any time.

CS6359 Fall 2012 John Cole 23

Page 24: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Constraints

• Constraints is a restriction on a UML element.• Shown as text between braces• {size > 0}

CS6359 Fall 2012 John Cole 24

Page 25: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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

CS6359 Fall 2012 John Cole 25

Page 26: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Association Class

• Allows you to treat an association as a class, such that it can have attributes

CS6359 Fall 2012 John Cole 26

Page 27: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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.

CS6359 Fall 2012 John Cole 27

Page 28: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

Template Classes and Interfaces

• These are equivalent to C++ or Java “generics.”

• That is, you can type a collection class.

CS6359 Fall 2012 John Cole 28

Page 29: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

User-Defined Compartments

• In a class diagram you can define your own compartments:

CS6359 Fall 2012 John Cole 29

DataAccessObject

Id: int

doX();

Exceptions thrownDatabaseExceptionIOExeception

ResponsibilitiesSerialize and write objectsRead and deserialize objects

Page 30: Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole

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.

CS6359 Fall 2012 John Cole 30