01.02.2013 Views

Software Development Cross Solution - Index of - Free

Software Development Cross Solution - Index of - Free

Software Development Cross Solution - Index of - Free

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.

don’t repeat yourself<br />

Your design should obey the SRP, but also be DRY...<br />

The SRP is all about responsibility, and which objects in your system do what.<br />

You want each object that you design to have just one responsibility to<br />

focus on—and when something about that responsibility changes, you’ll know<br />

exactly where to look to make those changes in your code. Most importantly<br />

you’ll avoid what’s called the ripple effect, where one small change to your<br />

s<strong>of</strong>tware can cause a ripple <strong>of</strong> changes throughout your code.<br />

But there’s a principle that goes hand in hand with SRP, and that’s DRY:<br />

160 Chapter 5<br />

Don’t repeat yourself<br />

Avoid duplicate code by abstracting or<br />

separating out things that are common and<br />

placing those things in a single location.<br />

The different Date classes are not DRY<br />

Each <strong>of</strong> the different Date classes (FirstDate, SecondDate, ThirdDate)<br />

have almost identical behavior in their validateEvent() methods. This not<br />

only breaks the SRP, but means that one change in logic—like specifying that you<br />

can actually Sleep Over on the second date—would result in changes to the logic<br />

in all three classes.<br />

FirstDate<br />

# validateEvent(event : Event)<br />

:boolean<br />

SecondDate<br />

# validateEvent(event : Event)<br />

:boolean<br />

These methods have nearly<br />

identical code......but this should be a single behavior, not<br />

three separate pieces <strong>of</strong> functionality.<br />

ThirdDate<br />

# validateEvent(event : Event)<br />

:boolean<br />

This quickly turns into a<br />

maintenance nightmare.<br />

DRY is about having each piece <strong>of</strong><br />

information and behavior in your<br />

system in a single, sensible place.<br />

Download at WoweBook.Com

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

Saved successfully!

Ooh no, something went wrong!