Advanced Concepts of UML Class Diagrams

Berner Fachhochschule Engineering and Information Technology Advanced Concepts of UML Class Diagrams Prof. Dr. Eric Dubuis Berner Fachhochschule, Eng...
Author: Sibyl Turner
4 downloads 0 Views 245KB Size
Berner Fachhochschule Engineering and Information Technology

Advanced Concepts of UML Class Diagrams Prof. Dr. Eric Dubuis Berner Fachhochschule, Engineering and Information Technology @ Biel Course "UML and Design Patterns" of module "Software Engineering and Design", version October 2009 (X)

BFH/TI/Software Engineering and Design/UML and Design Patterns/Advanced Concepts of UML Class Diagrams/October 2009 (X)/Prof. Dr. E. Dubuis

Page 1 of 22

Berner Fachhochschule Engineering and Information Technology

Session's Goals You'll learn: ●

More advanced UML class modeling concepts



Corresponding Java representations (in part)

BFH/TI/Software Engineering and Design/UML and Design Patterns/Advanced Concepts of UML Class Diagrams/October 2009 (X)/Prof. Dr. E. Dubuis

Page 2 of 22

Berner Fachhochschule Engineering and Information Technology

Readings ●







[Fowler]: UML Distilled, Martin Fowler, third ed., Addison-Wesley, 2004. ISBN 0-32119368-7. [Jeckle]: UML 2 glasklar, Mario Jeckle et al., 2. Auflage, Hanser Verlag, 2004. ISBN 3446-22952-3. See also: http://www.uml-glasklar.com [UML-Home]: http://www.uml.org/#UML2.0 [UML-Specification]: http://www.omg.org/technology/documents/modeling_spec_catalog.htm#UML

Not all readings are cited in the text that follows.

BFH/TI/Software Engineering and Design/UML and Design Patterns/Advanced Concepts of UML Class Diagrams/October 2009 (X)/Prof. Dr. E. Dubuis

Page 3 of 22

Berner Fachhochschule Engineering and Information Technology

Tagged Values or Keywords You can use tagged values (or properties) for better characterizing a modeling element: Examples of tagged values (or properties): ●

{abstract}: short-cut for {abstract = true} ○





use it for: abstract classes use it for: abstract operations (that is, operations without a method [UML jargon])

{ordered}: (see next slide)



...



{readOnly} indicates that clients may not modify the property.



BFH/TI/Software Engineering and Design/UML and Design Patterns/Advanced Concepts of UML Class Diagrams/October 2009 (X)/Prof. Dr. E. Dubuis

Page 4 of 22

Berner Fachhochschule Engineering and Information Technology



the {ordered} and {unique} property strings:

UML meta attributes isOrdered1 isUnique2 false false (default) false true (default) (default) true false

true

true (default)

Property String {bag}

UML Collection Type Bag

use Java Collection Type

{unique} or {set} or nothing {ordered, unique = false} or {sequence}3 {ordered, unique}

Set

Set

Sequence

List

OrderedSet

SortedSet

List, ...

1 Elements are ordered, definition of “≤” relation over elements must exist. 2 No duplicates in collection. 3 Not in the UML standard. BFH/TI/Software Engineering and Design/UML and Design Patterns/Advanced Concepts of UML Class Diagrams/October 2009 (X)/Prof. Dr. E. Dubuis

Page 5 of 22

Berner Fachhochschule Engineering and Information Technology

Stereotypes A stereotype is a mechanism to extend existing meta-classes of UML. You can add more precise information to a modeling element. A stereotype is defined for example: UML metamodel extension:

predefined stereotypes Class

persistent defined by you

metamodel extension relationship EJB3 code generator could generate:

Usage:

Customer - name : String - ...

import javax.persisistence.*; @Entity public class Customer { @Id private int id;

}

private String name; …

BFH/TI/Software Engineering and Design/UML and Design Patterns/Advanced Concepts of UML Class Diagrams/October 2009 (X)/Prof. Dr. E. Dubuis

Page 6 of 22

Berner Fachhochschule Engineering and Information Technology

Some Standard Stereotypes1 See a complete list of stereotypes: http://www.uml-glasklar.com/DownloadDB.nsf/(DDDownload)/JHAN-6DCATU/$File/19-1%20Standardstereotypen%20UML%202.0.pdf

Name «auxiliary» «call» («use») «create»

Scope class dependency operation

«create» «destroy» «metaclass» «enumeration» «type»

dependency operation class class class

«utility»

class

Meaning The corresponding class implements secondary logic. A more precise description of a dependency. The operation is used to construct an instance of the operation's class. The source creates instances of the target. The operation destroys the instance of this class. Instances of this class are classes, too. Instances of this class enumerate values. Allows to group instances that expose the same set of operations. You'll use an interface in Java. A class without instances, but having a set of constants and/or static operations.

1 The stereotype «use» is often used but seems not to be defined in one of the UML standard profiles. BFH/TI/Software Engineering and Design/UML and Design Patterns/Advanced Concepts of UML Class Diagrams/October 2009 (X)/Prof. Dr. E. Dubuis

Page 7 of 22

Berner Fachhochschule Engineering and Information Technology

Static Operations and Attributes An operation and/or an attribute that applies to a class rather than to an instance. In Java, you'll use the static keyword. static variable instance scope

Order + count : int + getNumber() : int + getNextNewNumber() : int

class method (class scope)

BFH/TI/Software Engineering and Design/UML and Design Patterns/Advanced Concepts of UML Class Diagrams/October 2009 (X)/Prof. Dr. E. Dubuis

Page 8 of 22

Berner Fachhochschule Engineering and Information Technology

Derived Properties Derived properties can be calculated based on other values. a comment or note Date Range + start : Date + end : Date

length = end – start

+ / length : Integer

can be calculated → derived property

BFH/TI/Software Engineering and Design/UML and Design Patterns/Advanced Concepts of UML Class Diagrams/October 2009 (X)/Prof. Dr. E. Dubuis

Page 9 of 22

Berner Fachhochschule Engineering and Information Technology

Aggregation and Composition ●

Aggregation: “member-of/part-of” relationship Example: Clubs and Persons *

Club

3..* +members

Person

non-exclusive! ●

Composition: exclusive “member-of/part-of” relationship sometimes: Example: Polygon and Points and Circles life cycle property is linked, too... Polygon dependency (see next slide)

1

3..*

Point {xor} exclusive!

1

1

Circle needed to express the fact that points are not shared among circles

BFH/TI/Software Engineering and Design/UML and Design Patterns/Advanced Concepts of UML Class Diagrams/October 2009 (X)/Prof. Dr. E. Dubuis

Page 10 of 22

Berner Fachhochschule Engineering and Information Technology

Dependency Relationship “A dependency is a relationship that signifies that a single or a set of model elements requires other model elements for their specification or implementation. ...” [UML-Specification] Notation: ●

Supplier depends on Client

general view: Client



Supplier

concrete example: Person

+m(s :String)

String

Person depends on String

BFH/TI/Software Engineering and Design/UML and Design Patterns/Advanced Concepts of UML Class Diagrams/October 2009 (X)/Prof. Dr. E. Dubuis

Page 11 of 22

Berner Fachhochschule Engineering and Information Technology

Some Special Kinds of Dependencies ●

Use:1



Clien ●

Trace:

Test Case 1 ●

e> > c a r t