Polymorphic functor stack design pattern
Hi All,
I wonder if I could pick up a few pointers (no pun!) on the following:
I have an algorithm (Markov-chain Monte Carlo for those who are
interested) which works on a high-dimensional space. The coordinates
in the space are updated iteratively by dividing them into groups, and
updating each group separately. There are a choice of updating
algorithms that can be used on each group. I have an abstract base
class "McmcUpdate" for the update algorithm interface, and derive
concrete update classes from this:
class McmcUpdate {
McmcUpdate(CoordinateGroup& coords, RNG& rng);
virtual
void
update() = 0;
};
class ConcreteUpdate : public McmcUpdate {
void update() { // do the update }
};
I then have a containing class "Mcmc" which has factory methods for
the user to create update instances for their choice of coordinates:
class Mcmc {
Mcmc(DataModel& data);
ConcreteUpdate* createConcreteUpdate(CoordinateGroup& coords) {
McmcUpdate* update
= new ConcreteUpdate(coords, rng_);
callstack_.push_back(update);
}
void iterate() { // iterate over the call stack here };
};
The issue is, I have various data members of Mcmc representing various
cached summary values for the coordinates as well as the methods used
to generate them. The McmcUpdate objects require access to all of
these, and the summary values change for each call of an McmcUpdate.
My only idea so far is to create a class of all the various data
members and pass this by reference to each McmcUpdate constructor.
However, this seems to require yet another class to act as glue.
Shouldn't it be possible to expose the members to the (contained)
instances of McmcUpdate (and children), whilst preventing access to
them from the user side of Mcmc?
I'm more than willing to post further if the above is not clear!
Thanks,
Chris
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]