56
These classes, and their publicly-accessible methods, will be
described below.
All of these classes have similarly-named header files (CNKObj.h,
CNKBuf.h, etc.) which are available in the include/cnkbase
directory.
CNKObj: Main
Parent Class
Almost all of the object classes inherit directly or indirectly from
CNKObj, a class containing several useful utility methods. This class
also introduces some style rules used in all of the other classes.
CNKObj::
CNKObj();
virtual ~CNKObj();
virtual void init();
Individual CNKObj objects can be created and destroyed, although
these objects are not very useful by themselves. Note that the
constructor has no arguments; this is true of all of the CNK object
constructors.
Objects are created and initialized as follows:
1. Create the object, calling the constructor with no arguments.
2. Set the object properties by calling class-specific methods.
3. Call
init() to initialize object using the properties.
Each subclass should redefine
init() to call its parent class init(),
and then perform whatever class-specific initialization is needed. For
example,
CNKBuf::init() starts by calling CNKObj::init().
There are several reasons for using this approach. First, it allows
object classes to have many properties, without having to maintain
constructors with all of these properties. Second, this simplifies the
Java-to-C++ communication facility. Finally, it allows an object to be
re-initialized, by changing properties and calling
init() again.
One downside of this approach is that one has to be careful not to use
an object between changing its properties and calling
init(), since it
may be in an inconsistent state.
CNKObj::
void setName(const char* name);
const char* getName();
Comentarios a estos manuales