[Insight-developers] Questions on Program Style/Design Functors/Function Parameters
Kent Williams
norman-k-williams at uiowa . edu
Mon, 2 Jun 2003 09:03:51 -0500
Thanks Luis. I have been looking at using a templated functor class, and=
I'll=20
look at the classes you suggest for the right style to implement. After=20
sending that E-mail I did start revising the class to use a functor templ=
ate=20
parameter.
The only open issue with using the Functors that I can see are these (unl=
ess=20
I'm misinterpreting the code):
1. Functors have to have a constructor that takes no arguments. An insta=
nce=20
of the Functor type is kept as private member data.
2. In the UnaryFunctorImageFilter template class, there are access functi=
ons=20
to set the Functor member, but since the member is an Instance, and not a=
=20
pointer or a reference, there has to be an exact class match; one can't p=
ass=20
in a derived class instance.
In practice, these are probably not onerous restrictions; they may in fac=
t=20
constrain programmers to not twist the system away from it's intended pat=
tern=20
with cute class derivations. But it does kind of itch at my designer's mi=
nd=20
that the Functor patten can't be completely general.
Issue 2 can be finessed by defining a functor with an Init function to pa=
ss in=20
configuration parameters, but that always bothers me a little since it al=
lows=20
a programmer to create an instance and forget to call the initializer.
Anyway thanks for the help!