Re: Advice on designing for IoC

peter-4lf8KW9E9MLMqX/[email protected] Tue, 13 Jan 2004 11:14:28 +1100
Newsgroups gmane.comp.java.jcontainer.interest
Message-ID <010401c3d96a$35870df0$21e7809d@fisg2>
Hiya,

I haven't looked at the code in detail but off the to pof my head the way I
would do it if I was you would be to organize it like the following;

* Create an XML config file DTD
* Create a VirtualMockConfig object that contains all configuration options
* Create a ConfigReader that reads config file and creates a
VirtualMockConfig object
* Create a VirtualMockRuntime that sets up the runtime and is passed a
VirtualMockConfig object
   (Alternatively create a VirtualMockRuntime and a RuntimeBuilder and pass
VirtualMockConfig to
   the RuntimeBuilder and setup/configure VirtualMockRuntime)

Note that in the above there is no static methods.

As the above is a PITA to setup and configure it may be best to create a
static utility class to help do all this in fewer steps. You may have
something like a

class VirtualMockFactory
{
  static VirtualMockRuntime createRuntime() {...} //May read default config
file from Classpath
  static VirtualMockRuntime createRuntime( InputSource in ) {...} //For ones
that use non-standard config file
}

As to whether it is useful to have lifecycle stages - I would not bother. It
is simpler to just ignore it - you may want to do something like following
but then again maybe not.

VirtualMockRuntime runtime = VirtualMockFactory.createRuntime();

Recorder r = runtime.createRecorder()
//setup calls with r
Playback p = r.compile();
//Do test
p.verify();

Anyways thats my guestimate from quick look.