Game Development Reference
In-Depth Information
generic framework must be able to support an interface that allows different func-
tions to be attached to it, depending on the work needed. There are two ways that
our framework will allow the worker function to be defined: through the use of
delegates and through the use of virtual functions accessible through inheritance.
Delegates, the equivalent to function pointers in C++, will allow our system to
specify the worker function without requiring inheritance. The delegate approach
should only be used in throwaway tools where time is more important than main-
tainability, because delegates generally promote bad design when compared to the
alternate OOP approach.
The other way that we will be able to specify the worker functions will be through
inheriting from the base framework class. A virtual function will be called when a
file is to be processed and the super class can take care of it appropriately.
For example, if you have a tool that has to recursively open all .txt files in a direc-
tory and replace occurrences of a certain phrase with another, you would create a
class that inherits from the base framework, and override the process method. In
this method, you would open the file, read in the text, perform the substitution,
and save the new text back to disk. All the code that handles the recursion, file
attributes, pattern matching, and other common I/O operations would be left to
the framework, loosely coupled from the tool itself.
The properties, events, and methods of the base framework class will be defined in
an interface to ensure strong OOP design. This will allow for a modular approach
to even the framework engine itself, if more than one engine is ever used.
A delegate will exist for progress notification, so that users will be able to watch the
status of the current operation.
The framework will also provide support for handling read-only files. The ability
to skip read-only files will be available, as will the ability to remove the read-only
attribute from the file before passing the file off to the worker function.
Implementation
Based on the above goals and proposed solution, the following two components
make up the batch file processing framework. See Tables 17.1-17.3 for description
of Delegate Definitions.
The following interface defines the properties, events, and methods that the frame-
work engine must realize. The code is quite simple, but I will go over the code for
the sake of clarity.
Search Nedrilad ::




Custom Search