Some years back when I was flying with Flying Samaritans, I was invited to a party for a fellow pilot in Beverly Hills, California. Since the party involved a good deal of celebration, I had to stay over—no way I was going to fly back to San Diego that evening. The house we stayed in was a classic early California-Spanish design; a beauty in every way. The next morning, bright and early, I went for a walk along well-tended streets where no pothole or crack in the pavement dared to show itself. The streets were immaculate, as were the sidewalks and everything between the houses along and off Beverly Drive.
A Humpty Dumpty Site
The other day, I was helping a group who was given a Web site to revive with Flash. The original site was done with PHP, and as I looked at the code, I was struck by the fact that the developer had written some beautiful algorithms in PHP and demonstrated a masterly control over PHP syntax. At the same time, I was struck by the fact that this Humpty Dumpty Web site couldn’t be revised by all the kings horses and all the kings men. A change in one part caused another part to fold and crumble. It was a true house of cards, albeit made with some beautiful cards.
That’s when the metaphor of Mansions in the Slum popped in my head. A lot of developers want to be better at what they develop, and yet while their algorithms shimmer and glow (like a big gorgeous mansion), the relations between the classes and their encapsulated algorithms are cluttered with junk, weeds or are wholly non-existent. When first encountering Design Patterns a lot of developers reasonably ask, How do design patterns make my programs run faster and better?. With few exceptions, such as the Flyweight Pattern, they answer is,
They don’t.
Design patterns help clear the junk and weeds out of the streets between the classes that have been so painstaking developed. Further, design patterns facilitate application maintenance. If you need a little maintenance work in Beverly Hills, it’s easy to get the repair crew in there to do the work, and the house next door isn’t going to collapse when the repair is complete. The community is kept in good shape by good maintenance and a good system of communication. If for some reason, no maintenance was able to get to the homes in Beverly Hills, in short order, the place would deteriorate. However, because of the attention given to the streets that connect all of the mansions in Beverly Hills, we can expect it to be an area of well-maintained homes for the foreseeable future.
So when designing an application, Web site or other program, don’t just think in terms of building great classes with slick algorithms. Think in terms of creating a community of classes where every class can easily relate to other classes but maintain a loose relationship. Not only will that help you maintain your work, but it will help you appreciate and understand what design patterns are all about. The fact that the patterns already have the class relations laid out for you just makes it all that much easier.

The Mansions in the Slum: The Case of Beautiful Algorithms and Disappointing Designs by William B. Sanders, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
Related posts:

Bill Sanders
Thanks for the analogy. I’m looking to familiarize more with Design Patterns. What is a good one to start with? Where can I see an example of it? What is “Flyweight Pattern”?
Thanks,
-B
Hi Brandon,
To get a good OOP background and foundational Design Pattern concepts, I’d suggest you start with Chapter 1. If you want to jump right into design patterns, Chapter 2 (Factory Method) or Chapter 11 (Strategy) are good choices.
On this blog, you can find several simple examples of Design Patterns. I would suggest you use the index on the right side of this blog and cruise through to see the ones available. (In the 100+ Posts we’ve got, you’ll have plenty from which to choose.) The Flyweight is presented in a multi-part post you can find in the index on the right →, but you might want to consider some of the others before you go to that one.
Kindest regards,
Bill
Hi William,
Thanks for the well-chosen yet not overly long or complicated parable – finally a nice blog post I can point people to who ask me the »faster or better« question.
Congratulations!
Hi Klickvebot,
Thanks for the kind words. Where things get “faster and better” with Design Patterns is when it comes time to update and change a program.
Kindest regards,
Bill