About UML

An important part of each pattern's description is a Unified Modeling Language[2] (UML) class diagram. UML is a universally accepted way of describing software in diagrammatic form. The diagrams in the book make use of the UML features itemized in Table 1-1.

Table 1-1. UML class diagram notation

Program element

Diagram element

Meaning

Class

Types and parameters specified when important; access indicated by + (public), (private), and # (protected).

Interface

Name starts with I. Also used for abstract classes.

Note

Any descriptive text.

Package

Grouping of classes and interfaces.

Inheritance

B inherits from A.

Realization

B implements A.

Association

A and B call and access each other's elements.

Association (one way)

A can call and access B's elements, but not vice versa.

Aggregation

A has a B, and B can outlive A.

Composition

A has a B, and B depends on A.

There are three kinds of blocks, for classes, interfaces/abstract classes, and packages. The class is the most common diagram element and contains details of some of its corresponding C# class's more important attributes (or fields) and operations (or methods). A UML diagram is not meant to be an exact copy of a program, and thus only the elements that are important to the pattern under consideration are shown. The accessibility of all attributes and operations (private, public, or protected) is indicated. The default for attributes is private and for operations is public. Deviations from the defaults will be highlighted as they occur.

The types associated with attributes and operations are not usually given. However, when these are important, they can be inserted after the identifier, separated by a colon. The same relaxed approach applies to parameters of methods, which are not usually shown in a diagram.

Notes are very useful for explaining relationships, such as when a method in one class calls a particular method in another, when this information is directly relevant to the pattern. In most cases, though, six types of lines give enough information. The Decorator pattern, which we will consider first, has a reasonably rich diagram, and it will be used to explain the lines in more detail.



[2] * Defined by the Object Management Group (see http://www.uml.org).

Get C# 3.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.