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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Strategy patterns, loose<br />

couplings, object stand ins...<br />

Suppose we used the strategy pattern again for all the different<br />

variations on the types <strong>of</strong> gift card a database could return, like this:<br />

Here’s a strategy<br />

that will make good<br />

gift cards...<br />

TestGoodDBAccessor<br />

+ getGC(gcId : int) :GiftCard<br />

+ saveGC(card : GiftCard) :void<br />

<br />

DBAccessor<br />

+ getGC(gcId : int) :GiftCard<br />

+ saveGC(card : GiftCard) :void<br />

TestInsufficientDBAccessor<br />

+ getGC(gcId : int) :GiftCard<br />

+ saveGC(card : GiftCard) :void<br />

Here’s one that will<br />

make a gift card with<br />

To avoid all these extra classes, you could have one<br />

TestDBAccessor implementation that returned different<br />

cards based on the ID you gave it, but that’s screwing up loose<br />

coupling. TestDBAccessor would have to be in sync with<br />

your test code to make sure they agree on what each ID means.<br />

TestInvalidDBAccessor<br />

+ getGC(gcId : int) :GiftCard<br />

+ saveGC(card : GiftCard) :void<br />

test-driven development<br />

MySQLDBAccessor<br />

+ getGC(gcId : int) :GiftCard<br />

+ saveGC(card : GiftCard) :void<br />

insufficient funds on it.Here’s one that will throw<br />

But each test gift card accessor<br />

shares a lot <strong>of</strong> code, and that’s<br />

bad, too...so what do we do?<br />

Download at WoweBook.Com<br />

Here’s the real<br />

MySQL accessor.<br />

an error regardless <strong>of</strong><br />

what ID you give it.<br />

you are here 4 303

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

Saved successfully!

Ooh no, something went wrong!