On Mon, Jan 18, 2010 at 9:23 AM, Sean Owen <sro...@gmail.com> wrote:
> You're suggesting the class choose between a regular and test-friendly
> RNG, by calling one of two methods. Doesn't that put the decision with
> the class instead of externally? Right now it's already external.
> RandomUtils decides what to instantiate.

I'm suggesting that the instantiator/caller of the class choose
between a regular and test-friendly RNG. In some classes that creator
will be a unit test in other cases the creator will be another piece
of production code. In some cases the decision as to which type of RNG
to use will need to be made further up the object graph than the
immediate instantiator/caller, and generally it should be made as
close to main() or setUp() as possible.

RandomUtils essentially achieves the same thing in a static fashion.
The class itself decides that it will always delegate to RandomUtils
and random utils provides the different strategies. Currently if
RandomUtils.useTestSeed() is called once in a VM all other callers of
RandomUtils.getRandom() will get a test seed.

Drew

Reply via email to