Showing Ownership: Composition


If you have a part instance of some whole instance which belongs to one and only one whole, then you have a special case of aggregation known as composition. With composition, parts can’t be shared with other objects. The life of the part is completely within the life span of the whole. If you think of a VCR, it is a composite. Take a look inside your VCR through the door that accepts the videotape. It is composed of all those internal parts—such as circuit boards, a power supply, and a tape-transport mechanism. If the VCR is destroyed, then all the parts within it are destroyed as well. When you have a part whose life is within the life of the whole, then you have composition, which is a strong form of aggregation. To indicate composition in UML, simply fill in the diamond that appears next to the class playing the role of the whole, as shown in Figure 5-1.

A typical real-world example is a client who needs to build a reporting system. Imagine such a system including a GenericReport class—a composite that contains several other classes. Figure 5-1 illustrates a simplified version of the class diagram that describes this composition. A GenericReport is composed of four parts—Header, Column, Body, and Footer. The diamonds are filled in with a solid color to indicate composition. Because composition is a kind of aggregation, and aggregation is a special form of association, you can place association names, multiplicities, role names, and qualifiers on the line between the classes. Notice that the body plays the role of detail. The multiplicity at the GenericReport end is 1 because these parts belong to one and only one instance of the composite object (GenericReport). Given a GenericReport there are zero or more instances of Header, one for each page of the report. A GenericReport has one or more Column instances, one or more Body instances, optionally a Footer.




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