Declaring and Defining Protocol Extension Classes

The Protocol Extension Example provides a simple illustration of protocol extension. It defines a “temperature” property protocol extension class. A default implementation is defined for AcDbEntity, and specific implementations are defined for AcDbCircle and AcDbRegion.

The example serves as a model for more complex (and realistic) uses of the ObjectARX protocol extension mechanism. The base class for this protocol extension, called AsdkEntTemperature, is derived from AcRxObject. This class defines the virtual functions that will be inherited by the derived protocol extension classes, AsdkDefaultTemperature, AsdkCircleTemperature, and AsdkRegionTemperature. In this example, there is only one function: reflectedEnergy(). The class hierarchy for the protocol extension classes is shown in the following figure:

The first step in using protocol extension is to declare and define each of the protocol extension classes. The base class, AsdkEntTemperature, is an abstract base class that is defined using the ACRX_NO_CONS_DEFINE_MEMBERS() macro. This class will eventually be registered as part of the ObjectARX class hierarchy.

The child classes are defined using standard C++ syntax for deriving new classes. These classes should not be registered in the ObjectARX class hierarchy, so you don't need to use the ObjectARX macros for them.

For each class, you implement the functions that constitute the protocol extension. In this example, each class has only one function, reflectedEnergy(), which calculates a temperature for the entity.