I stumbled upon the following comment in the .NET source code for the ItemsControl class.
In effect, the developer is saying–“I could do this a more elegant fashion. I just want everyone to know that this is ugly because I was told to do it this way”.
protected virtual void PrepareContainerForItemOverride(DependencyObject element, object item) { // Each type of "ItemContainer" element may require its own initialization. // We use explicit polymorphism via internal methods for this. // // Another way would be to define an interface IGeneratedItemContainer with // corresponding virtual "core" methods. Base classes (ContentControl, // ItemsControl, ContentPresenter) would implement the interface // and forward the work to subclasses via the "core" methods. // // While this is better from an OO point of view, and extends to // 3rd-party elements used as containers, it exposes more public API. // Management considers this undesirable, hence the following rather // inelegant code.
Who can blame him? I’ve written comments like this myself. Source code as confessional.