designing classes with similar goal but widely different decisional core
Posted
by
Stefano Borini
on Programmers
See other posts from Programmers
or by Stefano Borini
Published on 2011-02-15T12:48:58Z
Indexed on
2011/02/15
15:35 UTC
Read the original article
Hit count: 321
design
I am puzzled on how to model this situation.
Suppose you have an algorithm operating in a loop. At every loop, a procedure P
must take place, whose role is to modify an input data I
into an output data O
, such that O = P(I)
.
In reality, there are different flavors of P
, say P1
, P2
, P3
and so on. The choice of which P
to run is user dependent, but all P
have the same finality, produce O
from I
.
This called well for a base class PBase
with a method PBase::apply
, with specific reimplementations of P1::apply(I)
, P2::apply(I)
, and P3::apply(I)
. The actual P
class gets instantiated in a factory method, and the loop stays simple.
Now, I have a case of P4
which follows the same principle, but this time needs additional data from the loop (such as the current iteration, and the average value of O
during the previous iterations).
How would you redesign for this case?
© Programmers or respective owner