7.5 Generalization Hierarchies


An instance of a superclass always requires an instance of a subclass and vice versa. Consequently, the creation or deletion of an object classified as a leaf subclass, which implies all the object's parents, creates or deletes the instance of that subclass and all of its parent classes.

The syntax is the same as that of creating and deleting objects that are not in generalization hierarchies, except that in addition, an object may be a member of multiple hierarchies. Consequently, the object creation must list all the classes of which the object is a member, as indicated in Figure 7.11. Figure 7.12 shows some examples.

Figure 7.11. Creation, Deletion, and Reclassification in Hierarchies

graphics/07fig11.gif

Figure 7.12. Examples of Object Creation in Multiple Hierarchies

graphics/07fig12.gif

graphics/exclamation.gif

Some popular programming languages, such as C++ and Java, do not support a reclassification operation directly. Model compilers generate code to simulate the necessary behavior by creating an instance of the subclass and deleting the instance of the previous subclass.

The first line shows creation of an object newBook, which is an instance of BookProduct, which is in turn a subclass of Product, as shown in Figure 6.13 on page 97. To access attributes of the superclasses, access them as you would attributes of any object. The second block of statements initializes attributes of the object newBook as defined by the class BookProduct and its superclass Product.

The third statement block (of one line) creates an object multiBook, which is an instance of BookProduct and StockedProduct, both of which are (multiple) specializations of Product. The sole difference between this line and the first is the specification of the multiple leaf classes to which the object belongs. The example is based on Figure 6.18 (see page 102), which illustrates a compound generalization..

Definition: Reclassification is the act of moving an object from one leaf subclass in a generalization-specialization hierarchy to another.

When an object is reclassified, all the old subclass's attributes and associations go away, and new attributes and associations are established for the new subclass. Superclass attributes and associations and the attributes and associations of other subclasses are left unchanged.



Executable UML. A Foundation for Model-Driven Architecture
Executable UML: A Foundation for Model-Driven Architecture
ISBN: 0201748045
EAN: 2147483647
Year: 2001
Pages: 161

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