3 ms·
My general advice to anyone working with C# is the same advice given by the authors of Smalltalk to developers. 1) Always prefer composition and delegation to
by 1propionyl 7y ago
My general advice to anyone working with C# is the same advice given by the authors of Smalltalk to developers.
1) Always prefer composition and delegation to inheritance.
2) Always prefer interface inheritance to implementation inheritance even if in the short term it results in code clones.
3) If you intend to have multiple subclasses that adhere to the Liskov Substitution Principle, it is always better to have IFoo and X implements IFoo, Y implements IFoo... than it is to have abstract class Foo where X, Y extend Foo. You can still do that, behind the scenes, but your public interface should whenever possible be nearly entirely interfaces and concrete classes.
4) Inheriting the body/behavior of methods is seductive but ultimately only a poor excuse for not delegating that will create maintenance headaches down the line.