Download presentation
Presentation is loading. Please wait.
Published byMarilynn Walton Modified over 9 years ago
1
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Advanced UML Class Diagrams
2
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2 Objectives To present the portions of the UML class diagram notation not already covered To present examples to illustrate the use of the notation To present heuristics for using the notation well
3
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3 Topics Generalization Abstract and concrete operations and classes Interfaces Feature visibility Class and instance variables and operations Aggregation and composition Association classes and qualifiers Other association adornments More class diagram heuristics
4
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4 Generalization Generalization is the UML relation that holds between one model element (the parent) and another (the child) when the child is a special type of the parent. Represented by a hollow rectangle and lines Rectangle attaches to the parent and lines to the children Generalization is used in UML class diagrams to model inheritance.
5
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5 Generalization Example
6
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6 Generalization versus Association Generalization is a relation between classes. Associations represent relations on sets of class instances designated by the associated classes. Generalization is not a kind of association. They Never have multiplicities, Never have rolenames, Never have names (they already have a name: generalization).
7
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7 Abstract Operations and Classes An abstract operation is an operation without a body; a concrete operation has a body. An abstract class is a class that cannot be instantiated; a concrete class can be instantiated. A class Must be abstract if it has an abstract operation; May be abstract even if it has no abstract operations.
8
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8 Using and Representing Abstract Classes and Operations Abstract classes force their subclasses to implement certain operations. Abstract classes are represented in UML by Italicizing their names, Stereotyping them «abstract» or Giving them an {abstract} property. Abstract operations are represented in UML by Italicizing their specification or Giving them an {abstract} property.
9
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 Abstract Class and Operation Examples
10
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 10 Interfaces A UML interface is named collection of public attributes and abstract operations. Provided interfaces—realized by a class or component and represented by A ball (lollipop) symbol or A stereotyped class icon with a realization connector Required interfaces—needed by a class or component and represented by A socket symbol or A dependency arrow to a ball symbol or A dependency arrow to a stereotyped class icon
11
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 11 Provided Interface Notations
12
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 12 Required Interface Notations
13
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 13 Module Assembly Notations
14
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 14 UML Feature Visibility Public—Visible anywhere that the class in which it appears is visible; denoted by +. Package—Visible anywhere in the package containing the class in which it appears; denoted by ~. Protected—Visible in the class in which it appears and all its sub-classes; denoted by #. Private—Visible only in the class in which it appears; denoted by -.
15
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 15 Feature Visibility Example
16
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16 Class and Instance Variables and Operations An instance variable is an attribute whose value is stored by each instance of a class. A class variable is an attribute whose value is stored only once and shared by all instances. An instance operation must be called through an instance. A class operation may be called through the class. In UML class variables and operations are called static. Indicated by underlining an attribute’s or operation’s specification
17
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 17 Attribute and Operation Specification Examples
18
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 18 Aggregation and Composition The aggregation association represents the part-whole relation between classes. Denoted by a solid diamond and lines Diamond attaches to the aggregate (whole) while lines attach to the parts May have all association adornments The composition association is an aggregation association in which each part can be related to only one whole at a time. Denoted by a hollow diamond and lines
19
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19 Aggregation and Composition Examples
20
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 20 Problems with Aggregation Often abused Must be transitive: (x)(y)(z)((Rxy Ryz) Rxz) Often used for collection membership, which is not transitive Aggregation, composition, and collection membership can be represented by plain associations.
21
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 21 Association Classes An association class represents a relation on instances of the classes is connects, and it holds data and behavior. Association class connector is a dashed line Connects class with an association line There can be only one instance of an association class for each pair of instances of the associated classes. If more instances are need, interpose a new class (a reified association).
22
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 22 Association Class Example
23
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 23 Association Qualifiers An association qualifier is one or more association attributes that, together with instances of the qualified class, pick out instances of an associated target class. Represented by a box with association attributes and a line Attributes have standard specifications except that no initial values are allowed Box is attached to the qualified class Line runs to the target class Line can have association adornments
24
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 24 Association Qualifier Examples
25
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 25 Rolename Visibility Associations are often implemented using references. Rolename may be a reference attribute name Rolenames may have visibility modifiers (+, #, ~, -). Rolename visibility modifiers may be suppressed.
26
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 26 Association Navigability An association between classes A and B is navigable from A to B if an instance of A can access an instance of B; otherwise it is non- navigable. Navigability is denoted by adding an arrowhead to the association line in the navigation direction Non-navigability is denoted by placing an x on the association line in the navigation direction Navigability markers can be suppressed, so no markers means the diagram is silent on navigability
27
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 27 Rolename Visibility and Navigability Example
28
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 28 Class Diagram Heuristics 1 Never place a name, rolenames, or multiplicities on a generalization connector. Use the «abstract» stereotype and {abstract} property to indicate abstract classes and operations when drawing diagrams by hand; use italics when drawing diagrams on the computer. Use the interface ball and socket symbols to abstract interface details and a stereotyped class symbol to show details.
29
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 29 Class Diagram Heuristics 2 Don’t italicize interface or operation names. Show provided interfaces with the interface ball symbol or the stereotyped class symbol and a realization connector. Show required interfaces with the interface socket symbol or dependency arrows to stereotyped class symbols or interface ball symbols. Avoid aggregation and composition.
30
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 30 Class Diagram Heuristics 3 If aggregation or composition is used, check that the represented relation is transitive. Use association classes when only a single association class instance is associated with each pair of instances of the associated classes; otherwise use a reified association. Determine multiplicities involving a qualifier by considering qualified class instances and particular combinations of qualifier attribute values.
31
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 31 Summary UML class diagrams have great expressive power: they are able to show Generalization Abstract operations and classes Class and instance variables and operations Interfaces and interface assemblies Aggregation and composition associations Association classes and quantifiers Feature and rolename visibility Navigability
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.