Refactoring
  • Replace Inheritance with Delegation
    • A subclass uses only part of a superclasses interface or does not want to inherit data.
    • Your subclass violates the Liskov substitution principle, i.e., if inheritance was implemented only to combine common code but not because the subclass is an extension of the superclass.
    • The subclass uses only a portion of the methods of the superclass.
  • .NET and Multiple Inheritance
    • So what’s the solution? Often people are directed to using interfaces, but interfaces don’t lend themselves very well to meet the requirements of reusing code and implementing separation of concern; as interfaces are really intended to support polymorphism and loosely-coupled/contractual design.
    • But other than trying to tie behaviors into object inheritance hierarchies, there are many alternative approaches that can be evaluated to meet those requirements. For example, adopting relevant design patterns like Visitor, frameworks like MVC, delegates, mixins (interfaces combined with AOP), etc.
  • The reason to replace a modifier(such as static) with a constant(e.g. STATIC)
    • The modifier can be removed by a empty define
      • For production builds use -dSTATIC=static
      • For unit test builds use -dSTATIC
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License