This is my first StackOverflow question so be nice! 🙂
I recently came across the following example in some C# source code:
public IFoo GetFooInstance()
{
#IF DEBUG
return new TestFoo();
#ELSE
return new Foo();
#ENDIF
}
Which lead me to these questions:
- Is the use of “#IF DEBUG” unofficially deprecated? If not what is considered to be a good implementation of its use?
- Using a class factory and/or tools like MOQ, RhinoMocks, etc how could the above example be implemented?
Using an IoC container, the entire function becomes redundant, instead of calling GetFooInstance you’d have code similar to:
The setup of your IoC container could be in code or through a configuration file.