I am refactoring some inherited code that repeated the same thing many times using case case:
switch(identifier) case firstIdentifier: (SomeCast).SetProperties(Prop1,Prop2,Prop3); break; ... case anotherIdentifier: (SomeDifferentCast).SetProperties(Prop1, Prop2, Prop3); break;
So, I tried to create a unique interface so that it could become
(SameInterfaceCast).SetProperties(Prop1,Prop2,Prop3);
However, I found that some elements do not even use all the properties. So, I started thinking about something more similar:
if(item is InterfaceForProp1) (InterfaceForProp1).SetProp1(Prop1); if(item is InterfaceForProp2) (InterfaceForProp2).SetProp2(Prop2); if(item is InterfaceForProp3) (InterfaceForProp3).SetProp3(Prop3);
and you can create a class like this:
public class MyClassUsesProp2And3 : InterfaceForProp2, InterfaceForProp3
However, I am afraid that I will over-fragment this code and it may scroll too much. Maybe I should not be too afraid of what will be essentially one method interface, but I wanted to see if I have a design template before I go this way? (the only ones that arose in my head, but were not entirely suitable, were Decorator or Composite )
UPDATE
All properties are unique types.
Ultimately, it is an injection form of addiction. The code is too confusing to use something like Ninject right now, but in the end I can even get rid of some of them and use an injection container. Currently, there is also some logic that runs outside of the variable setting. This is all legacy code, and I'm just trying to clean it up a bit.