Connie's Convenience Store - About Peter Coad
Connie's Convenience Store - About Peter Coad
Connie's Convenience Store - About Peter Coad
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Establishing Responsibilities for Problem-Domain Objects Connie’s <strong>Convenience</strong> <strong>Store</strong> 51<br />
#116. “Describe Services with establishing responsibilities /<br />
a Template” Strategy what I do (descriptions)<br />
• Describe each service, using a template as your guide.<br />
input, output parameters<br />
description (including pseudo-code or actual code, detailing the algorithm to be<br />
applied)<br />
traceability codes to preceding documentation, if any<br />
visibility: public, protected, private.<br />
Here, consider what it takes to describe the “calculate total” services for sale and<br />
for sale line item.<br />
Using structured language, you can develop a description that looks something like<br />
this:<br />
sale.calcTotal ( ; total)<br />
calcSubtotal ( ; subtotal)<br />
calcDiscount (subtotal ; discount)<br />
total = subtotal - discount<br />
calcTax (total ; tax)<br />
total = total + tax<br />
sale.calcSubtotal ( ; subtotal)<br />
subtotal = 0<br />
for each saleLineItem that I know:<br />
saleLineItem.calcSubtotal ( ; lineItemTotal)<br />
subtotal = subtotal + lineItemTotal.<br />
Sale line item, revisited<br />
A sale line item may be for a sale or for a return.<br />
Do you need any specializations of a sale line item? Check it out. A generalization<br />
class shows “what’s the same.” A specialization class shows “what’s different.”<br />
Consider what’s the same, what’s different. In particular, with any kind of transaction,<br />
consider how much control, or lack of control, you have in the situation being<br />
recorded.<br />
You’ve got pretty good control over a purchase: you have the item, a customer<br />
wants to buy it; you’re in control.<br />
Returns are the real challenge: you’re getting an item you’ve had no control over;<br />
you don’t have as much control; a lot of unusual things can happen. For example:<br />
– A customer may return an item to a different location than where he purchased<br />
it.<br />
– A customer may return an item which had a different price when he<br />
purchased it.<br />
– A customer may return an item that Connie’s no longer carries.<br />
– A customer may return an item that was individually marked down, perhaps<br />
because it was slightly damaged.<br />
– A customer may return an item and be charged a return fee.