Question & Answer
Question
In IBM Rational Software Architect and IBM Rational Software Modeler, you can instatiate an abstract class. Why is this allowed, when abstract classes are not meant to be instantiated?
Cause
The following steps demonstrate how you can instantiate an abstract class:
1. Create a UML project and UML model
2. Create a class and mark it as Abstract in the Properties view
3. Create an object diagram and drag the class onto the diagram
Result: An instance is created, when it should not be created.
Answer
If you look more closely at the UML Superstructure v2.1 specifications under Section 7.3.22 InstanceSpecification (from Kernel), you will notice the following:
- under Description: "If the only classifier specified is abstract, then the instance specification only partially describes the entity."
- under Semantics: "When used to specify the existence of an entity in a modeled system, an instance specification represents part of that system. Instance specifications can be modeled incompletely — required structural features can be omitted, and classifiers of an instance specification can be abstract, even though an actual entity would have a concrete classification."
In other words, a model is not treated the same way as code.
In this case, therefore, you are allowed to instantiate an abstract class to represent the case of having an instance of a class that implements all the methods on the abstract class. The result is polymorphic behavior with a known, enforced interface specification.
Was this topic helpful?
Document Information
Modified date:
29 September 2018
UID
swg21416833