23.07.2012 Views

Design Patterns Explained

Design Patterns Explained

Design Patterns Explained

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 4 • A Standard Object-Oriented Solution 65<br />

In this case, I felt strongly that a better solution existed. Yet, two<br />

hours later, this was still the best I could come up with. The problem,<br />

it turned out, was my general approach, as will be seen later in this<br />

book.<br />

Pay attention to your instincts.<br />

Gut instinct is a surprisingly powerful indicator of the quality of a<br />

design. I suggest that developers learn to listen to their instincts.<br />

By gut instinct, I mean the sensation in your stomach when you<br />

see something you do not like. I know this sounds unscientific<br />

(and it is), but my experience has shown me consistently that<br />

when I have an instinctive dislike for a design, a better one lies<br />

around the corner. Of course, there are sometimes several different<br />

corners nearby and I'm not always sure where the solution is.<br />

Summary<br />

I showed how easy it is to solve this problem by special-casing<br />

everything. The solution is straightforward. It allows me to add<br />

additional methods without changing what I already have. How ever,<br />

there are several disadvantages to it: high redundancy, low cohesion,<br />

and class explosion (from future changes).<br />

The overreliance on inheritance will result in higher maintenance<br />

costs than should occur (or at least, than I feel should occur).<br />

In this chapter

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!