I am refactoring some legacy code that was doing close to the same thing over and over via a case statement:
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 this could become
(SameInterfaceCast).SetProperties(Prop1,Prop2,Prop3);
However, I then found that some items do not even use all of the properties. So, I began to think of something more like this:
if(item is InterfaceForProp1)
(InterfaceForProp1).SetProp1(Prop1);
if(item is InterfaceForProp2)
(InterfaceForProp2).SetProp2(Prop2);
if(item is InterfaceForProp3)
(InterfaceForProp3).SetProp3(Prop3);
and you could create a class like this:
public class MyClassUsesProp2And3 : InterfaceForProp2, InterfaceForProp3
However, I am afraid that I am overly fragmenting this code and it could balloon too much. Maybe I should not be too fearful of what will essentially be one method interfaces, but I wanted to see if I am missing a design pattern before going down this path? (the only ones that popped into my mind but were not quite the right fit were the Decorator or Composite patterns)
UPDATE
All properties are unique types.
Ultimately, this is a form of dependency injection. The code is too messed up to use something like Ninject right now, but eventually I might even be able to get rid of some of these and use an injection container. There is also currently some logic that is being done beyond just setting a variable. This is all legacy code, and I am just trying to clean it up little by little.