Overrides


Overrides

In C++, overriding of methods is simple: the superclass may declare a method to be virtual and a subclass may define a method with the same name and signature. The subclass' method then overrides that in the superclass.

In its simplest form, overriding operates much in the same way in CIM and either methods or properties may be overridden:

 class Superclass      {     string Name;      }; class Subclass : Superclass      {      [Override ("Name"), maxLen(15)]     string ShortName;      }; 

The property ShortName overrides (i.e., replaces ) the property Name when instances of the class Subclass are being addressed. In this definition I have taken the opportunity to restrict the maximum length of the name to 15 characters and this is a very common use of the Override qualifier.

Another common usage is to rename, and possibly restrict, an association. Consider the classes in Figure 10.3. Assume that instances of ClassA (and its subclasses) may have a very general association with instances of ClassB (and its subclasses) as shown: association assocA . Perhaps at this level we can only give very general terms for the two ends of the association such as "antecedent" and "dependent":

 [Association]  class assocA     {     ClassA REF Antecedent;     ClassB REF Dependent;     }; 

Figure 10.3: Association Overriding

By the time we reach the subclasses ClassA2 and ClassB1 we want to make use of this association but now we can give much more useful names to the endpoints. We can therefore override the association thus:

 [Association] class lowerAssoc : assocA      {     [Override ("Antecedent")]     ClassA2 REF LeftHandSide;     [Override ("Dependent"), min(1),max(1)]      ClassB1 REF RightHandSide;     }; 

We have tightened up the names and added the additional restrictions of max (1) and min (1).

These two examples illustrate one of the conditions of overriding ”you can only constrain the overridden entity more tightly, you cannot loosen it. Thus an unconstrained string as in my first example can have its length constrained to 15 characters or an association without constraints as in my second example can be constrained to max (1) but it would not be possible to specify the opposite .

To prevent overriding from constraining a property (or method ”anything that I say here about properties is also true of methods) there is a flavor which may be attached to a qualifier: DisableOverride . For example, the Association qualifier is defined as follows :

 Qualifier Association : boolean = false,     Scope(association),     Flavor(DisableOverride); 

which prevents anything which inherits from a class with the qualifier Association from removing that qualifier.




A Practical Approach to WBEM[s]CIM Management
A Practical Approach to WBEM[s]CIM Management
ISBN: 849323061
EAN: N/A
Year: 2006
Pages: 152

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