I have:
Several color classes, RGB, CMYK etc.
Each has the same 'ToGrey' methods (Desaturate, Decompose etc.)
Initially there was just one ToGrey method in each class which took a parameter to decide which actual method to use. I'm now implementing the strategy pattern in order to avoid having the switch statements in this earlier method.
Therefore I need to have:
A class for each ToGrey implementation.
An associated interface.
A contect class and an instance of that class in each color class.
However, each ToGrey implementation needs to take any one of several different color classes, so the method signature needs an interface rather than a color class and it needs to be the interface that permits type casting between the color types (since some ToGrey methods are RedChannel, BlueChannel etc.) hence asking for the RedChannel grey version of a CMYK or HSL color becomes possible, since I know I can convert the passed object to an RGB type. Either that or every ToGrey implementation needs to be overloaded with every color type.
That's starting to feel messy and hance the design must be wrong (I think).
Any ideas?
Addendum
==========
The next problem with the above thinking is that once I get an instance of a color (but which I must treat as the interface) and convert it to e.g. RGB in order to get the RedChannel then it's easy apart from when I need to convert it back to its original class type, since I have no idea what that was!
Thanks,
M