Deep class hierarchies are mind benders for all of us.
We're starting to see a lot more of them now, thanks to the "refactoring" mantra chanted by the "Design Patterns" and "Agile" gurus.
We happen to agree with those gurus. It really is worth refactoring code, most especially to purge it of the code duplication that undermines maintenance and testability.
"Extract Subclass" is the refactoring practice that often leads to multi-level class hierarchies. Do it often enough and you'll get an unpleasant profusion of classes, each in their own code files and often in separate assemblies that may not even be in your solution.
Here, for example, is an inheritance hierarchy for the application startup class called "ShellApplication":
These five classes are distributed among four separate projects only one of which is in your solution.
Class |
Project |
In Solution |
ShellApplication |
Shell |
Yes |
XtraFormApplicationBase |
DevExpress.CompositeUI |
No |
WindowsFormsApplication |
Microsoft.Practices.CompositeUI.WinForms |
No |
CabShellApplication |
Microsoft.Practices.CompositeUI |
No |
CabApplication |
Microsoft.Practices.CompositeUI |
No |
You look at "ShellApplication" and wonder "what are the members available to me?" and "why does this have to be so hard?"
When you see this happening to your code base, it's a good time to stop and ask if the trend is really paying off. Your code's intelligibility declines dramatically with every new level. Are there compensating benefits in maintenance, extensibility, and reuse? Are the benefits greater than the cost?
For many developers the easy answer is "NO WAY".
We feel your pain. Almost all of the good refactorings and design patterns (not just "Extract Subclass") result in more code files and more assemblies. It's a serious manageability problem.
On the other hand, we see the benefits and we are not ready to surrender. Perhaps there is a way to tame the complexity.
There is: a helpful Integrated Development Environment (IDE) makes all the difference. In fact, the "refactoring" movement would have gone nowhere without the new breed of IDEs to help us manage complexity.
Visual Studio 2005 is a leader among this new breed. All we have to do is learn how to use it. That takes some patience. There are a lot of great features. Some are hard to find. Some don't seem immediately useful, until a good friend shows you how to use it and you get that "aha!" moment.
Get ready for an "aha" moment: the Class View. You'll find it on the "View menu" (ctrl+shift+C).
|