Richard Zarr wrote:
We have a complex piece of code that has many discrete (unique)
classes that handle various tasks.
Typically you do this by defining a base task class that has a virtual
constructor and the set of task methods needed by all descendents
defined as virtual or even virtual abstract. You also define a class
reference type for this base class.
The individual task classes then descend from the base class and
override the virtual methods for their specific needs. The group class
can now just treat all task classes as instances of the base class, and
if each group class instance should only work with a specific task
class you pass that class to the group class constructor, where the
parameter is typed as the class reference type for the base task class.
Using that value the group class can create instances of the specific
task class.
If deriving all tasks from the same base class is impractical for some
reason you can achieve something equivalent by having each task class
implement a common interface. The place of the class reference type
would then be taken by a factory method that returns the interface for
the task object it creates.
--
Peter Below
TeamB
Connect with Us