Well, you can do something similar to my previous sentence, and also like a recursive sentence. For the functionality that you require in all three derived classes, you can create a single interface together with one class (call it the βexecutorβ for beats) that implements this interface (and which has the actual code that you want to execute on every call )
In each of your derived classes, you implement an interface and create a private instance of the executor. In each of the interface methods, you simply pass the call along with a private instance of Implementer. Since the implementation and your derived classes implement your interface, any changes you make to the interface will require you to modify the executor and the derived classes accordingly.
And all your code is in one place, with the exception of all the line passes that are called to a private copy of the artist (obviously, multiple inheritance would be better than that, but you go to war with the army you have, and not with the army that you would like to have).
Update : how easy is it to add a public instance of your class to each of the derived classes?
public class DerivedClass1 : ThirdPartyClass1 { public MyClass myClass = new MyClass(); }
Or, if you are interested in who Demeter is, and you get LOC:
public class DerivedClass1 : ThirdPartyClass1 { private MyClass _myClass = new MyClass(); public MyClass myClass { get { return _myClass; } } }
Then you simply call the MyClass methods as follows:
DerivedClass1 dc1 = new DerivedClass1(); dc1.myClass.DoSomething();
So we could all sleep.
source share