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

Create successful ePaper yourself

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

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

“Taxable” is a “yes/no” attribute, that is, it has the value “yes” or “no.”<br />

Check it out. “Taxable” is the name of a value: an item is “taxable” or “nontaxable.”<br />

Using a value as an attribute name is boring; it’s a “yes/no” kind of thing. Moreover,<br />

using a value as an attribute is unwise; as soon as you’ve got additional values, you’re in<br />

trouble; at that point, your object model will become more complex than it needs to be.<br />

Think about what happens at a store you visited recently. Are all items taxed at the<br />

same rate? Or do special taxes apply to certain categories of items?<br />

That’s it! Some categories of items may be taxable, while others are not. Instead of<br />

taxable, what an item object really needs to know is its tax category. Model that “need<br />

to know” with an object connection to tax category.<br />

Carefully examining each attribute does pay off. And writing attribute descriptions<br />

certainly gets one to consider that kind of detail. Based upon the added insight, here’s<br />

what item looks like now (Figure 1–27):<br />

Item<br />

number<br />

description<br />

shortDescription<br />

Figure 1–27: Item: “what I know.”<br />

Establish responsibilities: “who I know.”<br />

Who does an item object know?<br />

It knows:<br />

– UPC (zero or more).<br />

– price (zero or more).<br />

– tax category (zero or more).<br />

– sale line item (zero or more).<br />

Yes, each UPC, price, and tax category object knows its items. A sale line item<br />

knows its item, too (Figure 1-28).<br />

Establish responsibilities: “what I do.”<br />

Why do you need this abstraction, an item object?<br />

Certainly one reason is to remember the values of the attributes of an item.<br />

Yet there is a far more important reason why you might add an item object. And<br />

that reason is to capture some system dynamics. What does the system really need to do<br />

regarding its items?<br />

Hopefully, an item is something more than just a data holder. Look for something<br />

more than that.<br />

What can this abstraction do for you?<br />

Apply the “do it myself” strategy. Here it is again (it’s important):

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

Saved successfully!

Ooh no, something went wrong!