I am working on a game project using Microsoft XNA framework, although this question is a generic one that involves decoupling of classes/systems.
Let's say i have a class (simplified to suit this example) as shown here:
public class GameCell
{
public Color Color { get; set; }
}
I would like to reuse as much code as i can between multiple platforms that use C#.
The problem of directly referncing the Color struct is that this type is defined in the XNA assemblies, creating a strong coupling (or dependency) between my code and XNA.
The other framework i will be using may (or may not) have its own Color object, with its own set of properties and API.
I would like to have the same source file "know" to use either the XNA or other framework's implementation automagically.
I know other types of decoupling methods such as IoC, but that would mean i would be plugging in different versions of a system/class, instead of reusing the same class in different contexts.
Is this even possible to do? how would u suggest to keep such a system portable?
I've seen some cases (in native C++ development) where you would define a set of classes that mirror the classes the framework you're using has (for example here - define Color again), and so it is possible to "re-map" this later on to use different classes, upon need.
Another option is to mess around using #IFDEF to play with the using statements in the header of the class (switching from XNA to other platforms). What is the best alternative in this case?