Using Alternate Composite Notation


UML allows you to place a class diagram inside a class. When we’re talking about composites, this isn’t as strange as it may seem. Since the second compartment of a class shows structure, and a composite has complex structure within itself, then you can show the parts of the composite inside as a mini class diagram.

UML2 UML 2 has a new diagram name for this alternative notation: composite structure diagram.

Remember The UML notation for class has three major compartments:

  • The first compartment names the class, describes its stereotype and lists its properties.

  • The second compartment shows the structure of the class as a list of attributes.

  • The third compartment is where you place the class’s behavior specification.

This compartmentalization was allowed as an interesting idea in the previous version of UML 1.4. Most of the CASE tools, however, didn’t pick up on this idea. But that is changing with UML 2.0.

Showing parts as classes

Modeling the strong form of aggregation—composition—often results in a class diagram with lots of confusing lines. You have lines between the class playing the role of the whole and classes playing the role of the parts. You also have lines showing the associations between individual parts internal to the composite. With all these lines, the diagram can be difficult to read. UML 2 allows you to model composites and their parts as a class diagram within a class (composite structural diagram). This reduces the clutter and allows you to be clear about what you mean.

You can show the parts of a composite inside the structure compartment of a class by putting a box around the part and providing a name for that part: part name, then a colon, then a class name for the part. If you have more than one part of the same type in the composition, then you can show its multiplicity in square brackets. For example the Body part of a GenericReport would be surrounded by a box with detail:Body[1..*] inside, as in Figure 5-3.

click to expand
Figure 5-3: Composite parts shown inside a class.

Parts can also be connected by (you guessed it) connectors—lines that indicate links between instances of parts within a composite—so those parts may communicate with each other. UML 2.0 provides for two kinds of connectors—assembly and delegation. An assembly connector allows one part of the composite to supply services that another part needs. On the other hand, use a delegation connector to show the whole composite forwarding some external request for behavior to one of its internal parts. The assembly connector connects two parts like an association. The delegation connector connects the whole with one of its parts. The delegation connector is shown as a line from the edge of the composite class to one of the parts inside the composite class.

Figure 5-3 illustrates just such a diagram. The GenericReport class is playing the role of the whole or composite. The parts are anonymous parts with classes named Header, Column and Footer. One of the parts is named detail which is of the class Body. The parts are connected using lines that can be named just like associations. Indeed you can place multiplicity, role names, and qualifiers on these connections. Each of the connections shown in Figure 5-3 are assembly connections. For instance the Header will invoke the print service of Column.

Showing parts as attributes

This section ties together composites, part diagrams (those class diagrams inside of a class), and attributes. Figure 5-4 shows the class for GenericReport and its attributes. Notice the correspondence between the attributes in Figure 5-4 and the classes in Figure 5-3. The class definition in Figure 5-4 hides the internal structure of the GenericReport class by simply listing the major parts as attributes. The sqlStatement is not a part—rather, it’s one of the attributes of the GenericReport class.


Figure 5-4: Showing composite parts as attributes inside a class.

If you want to convert a simple class into a composite structure diagram, you can use Table 5-2 as a guide. The table shows the correspondence between attributes in a simple class diagram and the elements of a part diagram inside of a composite class. For instance the detail attribute of the GenericReport becomes a part with the same name in the composite structure diagram. The Body datatype becomes the name of the detail part’s class. The [1..*] multiplicity is carried forward to the multiplicity of the detail part.

Table 5-2: Attribute Correspondence to Composite Parts

Attribute Feature

Composite Structure Feature

Attribute name

Part name

Type

Part’s class name

Multiplicity

Allowable number of connections between part instances




UML 2 for Dummies
UML 2 For Dummies
ISBN: 0764526146
EAN: 2147483647
Year: 2006
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net