design question

G

Gert Van den Eynde

hi,

i'm writing a numerical quadrature class and could use some help on the
design. a numerical quadrature needs two "algorithms": the quadrature
method and (possibly) a variable transform. QuadMethod could be trapezoid,
romberg, etc... VarTrans could be None (no transform), TANH, IMT, ...

the client code should be able to provide an object of a certain class A
(not necessarily fixed which class, any class should do) and indicate what
member function should be used as its "evaluator" (i don't want to be bound
to operator(), but it should have a signature double MF(double) ).

so what happens is that the QuadMethod needs to evaluate the MF in a point,
this point should first be transformed by the VarTrans and then passed to
the object's MF. Side question: is it possible to prepend several VarTrans
objects? suppose i first want to do VarTrans1, followed by VarTrans2... how
would i have to design these nested VarTrans's?

what i have in mind now is two "strategy" patterns (GoF) for QuadMethod and
VarTrans using two abstract base classes...Maybe strategy using
templates...

any better ideas?

how do i construct the Integrator object (being a composition of a VarTrans,
QuadMethod and taking this object's member function MF)? i suppose the
Integrator class should be templated with class A? Or not ?

thanks,
gert
 
M

mlimber

Gert said:
hi,

i'm writing a numerical quadrature class and could use some help on the
design. a numerical quadrature needs two "algorithms": the quadrature
method and (possibly) a variable transform. QuadMethod could be trapezoid,
romberg, etc... VarTrans could be None (no transform), TANH, IMT, ...

the client code should be able to provide an object of a certain class A
(not necessarily fixed which class, any class should do) and indicate what
member function should be used as its "evaluator" (i don't want to be bound
to operator(), but it should have a signature double MF(double) ).

so what happens is that the QuadMethod needs to evaluate the MF in a point,
this point should first be transformed by the VarTrans and then passed to
the object's MF. Side question: is it possible to prepend several VarTrans
objects? suppose i first want to do VarTrans1, followed by VarTrans2... how
would i have to design these nested VarTrans's?

See the function composition objects in Josuttis' book:

http://www.josuttis.com/libbook/fo/compose11.hpp.html

It will let you easily compose two functions f(x) and g(x) into f( g(x)
).
what i have in mind now is two "strategy" patterns (GoF) for QuadMethod and
VarTrans using two abstract base classes...Maybe strategy using
templates...

any better ideas?

It sounds fine to me, but it's hard to say if there's a better way
without knowing more.
how do i construct the Integrator object (being a composition of a VarTrans,
QuadMethod and taking this object's member function MF)? i suppose the
Integrator class should be templated with class A? Or not ?

Perhaps the same composition functor above will help.

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Class design (again) 2
Read / Write Pattern Design 4
overloading operator << design question 2
Good design question 2
A design question .... 1
design issue 14
Design Question 13
file converter design pattern 1

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top