Tuesday, July 16, 2013

How do you like your noodle baked? medium or well done?

The second reason to avoid this is simply because it bakes the noodle of anyone who reads the code. - Eric Lippert
So when I see the following... I want to scream, yell, and run away.

public abstract class BusinessListBase<T, C> : ExtendedBindingList<C>, IEditableCollection, IBusinessObject, ISupportUndo, IUndoableObject, ICloneable, ISavable, IParent
        where T : Csla.BusinessListBase<T, C>
        where C : Csla.Core.IEditableBusinessObject
     // ... other code
public abstract class CompanyBusinessBaseCollection<T, TCollection> : BusinessListBase<T, TCollection>
        where T : Csla.BusinessListBase<T, TCollection>
        where TCollection : Csla.Core.IEditableBusinessObject
     // ... other code
Take note... that that's 2 levels of abstract class so far.. climbing the chain we have: Csla.Core.ExtendedBindingList<T> (where T now means C), System.ComponentModel<T>. I only stopped once I hit the framework inheritance chain start.
I just had to get that out...
Now to find references to cite on my rant:
  • since inheritance is a very intimate (and encapsulation breaking) relationship, it's easy for subclasses to effectively break their superclasses by, for instance, omitting necessary behavior when they the methods are called - Martin Fowler - Designed Inheritance
  • In fact, the Object-Oriented Design Patterns book from "the gang of four" has this to say about inheritance: Prefer object composition to class inheritance
  • Inheritance is pretty enticing especially coming from procedural-land and it often looks deceptively elegant. I mean all I need to do is add this one bit of functionality to another other class, right? Well, one of the problems is that inheritance is probably the worst form of coupling you can have. Your base class breaks encapsulation by exposing implementation details to subclasses in the form of protected members. This makes your system rigid and fragile. The more tragic flaw however is the new subclass brings with it all the baggage and opinion of the inheritance chain. Why does a model that enforces validation attributes care how the model is constructed? The answer is it shouldn’t, and to add insult to injury, the better design is actually easier to implement. Listen closely and you may hear the wise whispers of our forefathers… - Inheritance is Evil: The Epic Fail of the DataAnnotationsModelBinder
  • Prefer object composition to class inheritance - JsPatterns.com - A case against inheritance
  • Joshua Bloch hits it on the nail in his Effective Java book item about “Favoring composition over inheritance.” - The Shyam - Is Inheritance Overrated? Needed even?


  1. Ouch... just ouch...

    I wonder how messy the overlap between ISupportUndo and IUndoableObject might be. In name alone they seem redundant.

  2. I think there will be more posts about Csla.net. It's giving me logical seizures.