310 likes | 532 Views
Advanced UML Class Diagrams. 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. Topics. Generalization
E N D
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
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
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.
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).
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.
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.
Interfaces A UML interface is named collection of public attributes and abstract operations. • Providedinterfaces—realized by a class or component and represented by • A ball (lollipop) symbol or • A stereotyped class icon with a realization connector • Requiredinterfaces—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
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 -.
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
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
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.
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).
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
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.
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
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.
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.
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.
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