20.02.2013 Views

Connie's Convenience Store - About Peter Coad

Connie's Convenience Store - About Peter Coad

Connie's Convenience Store - About Peter Coad

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.

44 Connie’s <strong>Convenience</strong> <strong>Store</strong> Establishing Responsibilities for Problem-Domain Objects<br />

#86. “Do It Myself” Strategy establishing responsibilities /<br />

what I do (fundamentals)<br />

• This is an aspect of a software object coming to life: “I do those things that are normally<br />

done to the actual object that I’m an abstraction of.”<br />

• Here’s why. “Doing it myself” encapsulates attributes with the services that work on those<br />

attributes. That results in lower coupling and stronger cohesion.<br />

• If you are building a simulation system, then a software object will mimic what an actual<br />

object does. In most systems, this is not so. Software objects do those things that the<br />

system is responsible to do with regard to that object.<br />

Consider the actions done to a real item. Then turn them around, letting your abstraction,<br />

the one that comes to life in software, actually do those actions to (or for) itself.<br />

List some of the things done to an actual object (in this case, an item):<br />

– figure out the price for a given date- calculate a total for a given number<br />

of items.<br />

So let the item abstraction do something useful for you:<br />

– get price for date<br />

– how much for quantity.<br />

You could just ask for the price. Yet “how much for quantity” is a good way to encapsulate<br />

quantity-sensitive pricing for an item.<br />

Add item responsibilities to your object model (Figure 1-28):<br />

SaleLineItem<br />

Item<br />

1 n<br />

number<br />

description<br />

shortDescription<br />

n 1<br />

getPriceForDate<br />

howMuchForQty<br />

n n<br />

1 n<br />

UPC TaxCategory<br />

Figure 1–28: Item: “what I know; who I know; what I do.”<br />

Price

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

Saved successfully!

Ooh no, something went wrong!