Using Generalization Sets


Each generalization relationship is known as a binary relationship because the generalization relates two classes: the superclass and a subclass. When you create an inheritance hierarchy, you also create a generalization set—a concept that helps you discriminate among the subclasses that inherit general characteristics from a common superclass. For example, the basis for distinguishing among the subclasses of PrintMedia is the material form of each printed medium—whether a book, magazine, or transcript.

In our example of PrintMedia there are two generalization relationships, one between Book and PrintMedia and the other between Transcript and PrintMedia. These two generalization relationships then form a generalization set (known in earlier versions of UML as a discriminator), which is a characteristic that distinguishes individual specializations of a class into subclasses. The basis for this particular generalization set is the physical form of the printed material.

You can show the basis for discrimination among subclasses in UML. Just place the name of the generalization set (discriminator) close to the hollow arrowhead. Figure 6-4 shows the name of the generalization set to be physical form.

click to expand
Figure 6-4: Inheritance showing generalization set.

 Tip   You should use named generalization sets when you have large inheritance hierarchies. This will make it easier for others to know the basis for each part of your large hierarchy. If you ever have to add a class into your hierarchy at a later time, you can make the right decision as to what part of hierarchy the class belongs so your inheritance hierarchy remains consistent.

We experienced just such a problem with the materials in the archive. Figure 6-5 shows just the superclasses and subclasses for archive material and their basis for discrimination into generalization sets. (We’ve hidden the attributes and operations to make the diagram easy to read.) The ArchiveMedium are classified by the mechanism used to create them (creation mechanism). RecordedMedia are created using some recording device. PrintMedia are created using a machine that places ink on paper such as a printing press, photocopier, or typewriter. Videotape and CompactDisc are types of RecordedMedia based on their physical form.

click to expand
Figure 6-5: Complex hierarchy with generalization sets.

Okay, now we have a nice inheritance hierarchy—everything fits. Then, someone remembers that some old photos are also part of the archive. Photos are not made using a recording device, nor are they created putting ink to paper. Photos have a different creation mechanism and they are a different physical form from the classes in the hierarchy. However, because we have names for our generalization sets, we can see where to place the new class in the hierarchy.

In order to solve the problem, we need add a new class, so we add PhotoMedia as a kind of ArchiveMedium and Photograph as a kind of PhotoMedia. You create PhotoMedia with a camera and film, and then develop the film to reveal a picture. Understanding the basis for discriminating between the subclasses of ArchiveMedium helps place the Photograph class into the complex inheritance hierarchy, as in Figure 6-6.

click to expand
Figure 6-6: Using generalization sets to help with class placemen.




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