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.

62 Connie’s <strong>Convenience</strong> <strong>Store</strong> Working Out Problem-Domain Dynamics with Scenarios<br />

Here are some scenario view conventions and notes:<br />

– The “recognizer” object is in the left-most column.<br />

– The first service in the scenario is listed immediately below the “class<br />

with objects” symbol, in that first column.<br />

– A sending service is the service name that precedes the tail of a message<br />

arrow. Within an object symbol, when you need to explicitly identify<br />

which service is the sending service, use square brackets, identifying<br />

the sending service.<br />

– The argument list consists of inputs, followed by a semicolon, then outputs.<br />

Now expand this scenario. What does it take for a sale to calculate its subtotal?<br />

Remember the pattern at work here. Sale–sale line item is an instance of the transaction–transaction<br />

line item pattern.<br />

A sale tells each of its items to calculate its total.<br />

Does a sale line item know enough to calculate its total? No. What else does it<br />

need? It needs the item’s price. Who knows the price? An item does (indirectly; it needs<br />

to work with its price objects).<br />

What do you really want an item to do for you? Instead of giving you a value, what<br />

answer or what result do you need? It’s this: how much for quantity and date.<br />

Now we’re getting somewhere. That’s one of the system features. Yes!<br />

Work out the scenario view, this time for sale, sale line item, and item (Figure 1–40):<br />

Sale<br />

calcTotal<br />

calcSubtotal<br />

calcTax<br />

calcTotal<br />

calcSubtotal<br />

[calcTotal]<br />

calcTax<br />

n<br />

SaleLineItem<br />

calcSubtotal<br />

calcSubtotal<br />

howMuchForQty<br />

getPriceForDate<br />

Figure 1–40: The “sale calculates its total” scenario view (round II).<br />

Here’s how to read it:<br />

A sale object is told to calculate its total.<br />

The “calcTotal” service invokes the “calcSubtotal” service.<br />

Item<br />

howMuchForQty<br />

getPriceForDate<br />

Scenario: sale calculates its total.<br />

Scenario constraint:<br />

0.1 seconds, 9 out of 10 times,<br />

0.5 seconds max.<br />

sale.calcTotal ( ; total)<br />

sale.calcSubtotal ( ; subtotal)<br />

saleLineItem.calcSubtotal ( ; subtotal)<br />

item.howMuchForQty (qty, date ; amt)<br />

item.getPriceForDate (date ; price)<br />

sale.calcTax ( ; totalTax)

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

Saved successfully!

Ooh no, something went wrong!