Re: OON: "Subclassing" algorithms

From: Steve R. Karmesin (karmesin@acl.lanl.gov)
Date: Thu Apr 24 1997 - 11:45:48 EST


Konrad Hinsen wrote:
[snip]
> Suppose I have an algorithm for a specific problem, and an
> implementation that works. Now I want to tackle a similar problem that
> can be solved by a similar algorithm. All it takes is perhaps the
> modification of one step, or the addition of one. I would like to be
> able to "inherit" the working implementation while just replacing or
> adding small parts of it. And of course I do not want to modify the
> existing (supposedly well tested) code.

Take a look in the Design Patterns book (Gamma, Helm, Johnson &
Vlissides, Addison Wesley, 1995). The Template Method seems to be
along the lines you are looking for.

The general idea is that you put the general structure of an algorithm
in a base class, and override virtual functions in subclasses to modify
parts of the algorithm while leaving the rest intact.

And, if you haven't taken a look at this book before, I highly reccomend
it generally.

Steve Karmesin
karmesin@acl.lanl.gov



This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:05 EST