views:

40

answers:

1

I'm not doing much new development right now, but a lot of refactoring of older C# subsystems whose original requirements no longer support new and I'll add unexpected requirements. I'm also now using Rhino Mocks and unit tests where possible (vs 2008).

The dilemma for me is that to make the methods testable and mockable, I need to define clear "contracts" using interfaces. However, if I do this, a lot of the global data that many of the classes use turns into tramp data, passed from method to method until it gets to its intended user; this looks ugly, and is against my sensibilities, but ... can be mocked. Making a mixed bag class with a lot of static global properties is a more attractive option but not Rhino testable. Is there a middle ground between the two? Testable but not too trampy? Pattern perhaps?

You should also understand that these applications run on an in-house corporate developed platform, so there are a lot of helper classes and services that are instantiated once per application, and then are used throughout the application, for example a database accessor helper class. Another example is using configuration files that are read once, and used throughout the application by different methods for various reasons.

Your thoughts appreciated. Thanks - Old Man.

+3  A: 

What you might want to look at here is some form of the Service Locator Pattern. Make them classes find their own tramps.

Some other reasonable options would include wrapping up the bulk of the commonly used stuff in an "application context" class of some sort.

You also might wish to look into dependency injection if you haven't done so yet.

Wyatt Barnett
+1 application context class
le dorfier