I have a problem with using the right inheritance-chain without loosing good parts of the DRY-principle.
Given the following structure:
- abstract class A is my base for all classes
- abstract class B : A is my base for all classes that can have special features (made available through B)
Now, I need to have two new classes which share the same features. But one is of type A whilst the other one is of type B. (This can not be changed!) Both classes should have a method SetSize().
Question: How would I create a base-class, intermediate layer to have the SetSize()-method only declared/implemented once (DRY)? I guess something about using interfaces or some static helper-classes to implement the logic of SetSize()?
Are there any patterns or best-practices to achieve this behavior?
Aucun commentaire:
Enregistrer un commentaire