Chapter 4
The Header File
iSimplePlug Documentation
The header file is where a class is declared. That is, a header file contains an outline of information about the class, which the compiler must know. For the SimplePlug
class, the following must be declared:
SimplePlug
class.(For new programmers, a superclass is sort of like a class we will be extending, and an instance variable is a variable that is available from anywhere in a class (and is unique to each induvidual instance of a class)).
A good place to start, then, is to give the information from the list above:
The superclass of SimplePlug
is the ITPlugin
class. This class, defined in ITFramework, is the superclass for all plugins. It implements some essential methods for plugins, defines default behaviour for optional methods, and supplies some convenience methods to make plugins easier to write.
In our example, we will only use two instance variables. They are commandNameArray
and commandIDArray
. The variable commandNameArray
is an NSArray
of the commands our plugin will respond to, stored as NSString
s. The variable commandNameArray
is a pointer to a C Array that will be used to cache the numeric ID assigned by iTonamaton to each of the commands in commandNameArray
. More about these variables will be discussed as the tutorial progresses.
Lastely, we list all the methods the class implements. Actually, this would be overkill. Methods listed in the header file for any of the classes in the inheritence chain of a class need not be declared in Obj-C header files. (In English, that means that SimplePlugin
need not implement methods in its superclass ITPlugin
, or its superclass NSObject
. As it turns out, the only method for SimplePlug
that is new to this particular class is processCommand:
, which takes an NSNotification
that notifies us that a command was recieved by iTonamaton, and then processes the command. This method will never be called by us; instead we will tell iTonamaton to call it when a command needs to be processed.
Before putting this all together, we must note that iSimplePlug depends on both the Foundation framework, and the ITFramework framework, and thus the appropriate header files must be imported in order for the compiler to recognize classes, methods, and constants declared in these frameworks.
Thus, putting together everything said in this chapter, the decleration for the SimplePlug
class (Which is placed in the file "SimplePlug.h") then contains the following:
#import <Foundation/Foundation.h>
#import <ITFramework/ITFramework.h>
@interface SimplePlug : ITPlugin
{
NSArray * commandNameArray;
unsigned * commandIDArray;
}
- (void)processCommand:(NSNotification *)note;
@end
We see then, that the header file imports the necessary header files from the necessary frameworks, declares the class to use the ITPlugin
as the superclass, defines the two desired instance variables, and then declares the desired method. (Note that the processCommand:
method decleration tells us that the method takes an NSNotification
, and returns nothing.)
[back]
[TOC]
[forward]
Last Modified: $Date: 2003/12/16 01:29:33 $ by $Author: paploo $