Re.Mark

My Life As A Blog

Even More Independence

leave a comment »

In my post last week I discussed a solution for having control over the class being created by the class being tested. There is another way of doing this that is worth mentioning: creating a Factory class. Let's assume we created an interface (IBar) that our Bar class implements. Now we need to create a class (BarFactory) that contains methods for creating instances of Bar. I am inclined to take this one step further and create an interface for the factory class (IBarFactory which will create instances of IBar.) Now we can pass an instance of IBarFactory to Foo in the constructor. We can mock IBarFactory and ensure that we are only testing Foo.

Advertisements

Written by remark

May 6, 2006 at 10:56 am

Posted in Design

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: