Re: on a design question using C++
On Feb 5, 4:40 pm, Michael DOUBEZ <michael.dou...@free.fr> wrote:
puzzlecracker wrote:
[...]
From the pure design point of view, IMHO it makes sense to
separate the algorithms from the need to have a polymorphic
behavior.
In a very real way, you have polymorphic behavoir, anyway you
look at it. The question is whether resolving the polymorphism
at compile time has any advantages or not. The template method
pattern lends itself very well to compile time resolution, for
example; instead of deriving and to implement pure virtual
functions called by the "generic" class, the generic class is a
class template over a traits class, which provides the
functions.
In general, compile time resolution is less flexible (in cases
like this, anyway); on the other hand, if he's calling the
functions in a tight loop (and since this seems to be a numeric
application, that's a distinct possibility), compile time
resolution can result in significantly faster code. And if
you're even moderately familiar with templates, it's also likely
to be simpler code (although in this case at least, the
difference is very, very slight).
It is not like there was a specific contract or a domain
specific constraint between MyClass and mathematical models.
The generic class or the polymorphic class do have a contract.
--
James Kanze