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.

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

Cash drawer<br />

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

What does a cash drawer object know? It knows its:<br />

– balance<br />

– position (open, closed)<br />

– operational state (okay, jammed, missing).<br />

An important note about operational state<br />

Whenever an object represents an interacting system or device, it needs to know its “operational<br />

state.” You’ll need to add service descriptions that portray state-dependent behavior<br />

(keywords: precondition, trigger, terminate, postcondition).<br />

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

A cash drawer object knows its:<br />

– register.<br />

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

What does a cash drawer do?<br />

– open.<br />

When you tell a cash drawer object, an abstraction, to open itself, what happens?<br />

The cash drawer object sends an electrical signal to the actual cash drawer device, activating<br />

it, so it will open.<br />

(<strong>Peter</strong>) Hey, Connie, how about a cash drawer that closes automatically?<br />

(Connie) Nice idea, especially if someone leaves their drawers open in public.<br />

(Sorry about that.) Anyway, automatically closing cash drawers are not available.<br />

Go ahead and add cash-drawer responsibilities to your model (Figure 1–30):<br />

Register<br />

1 1<br />

CashDrawer<br />

operationalState<br />

position<br />

balance<br />

Figure 1–30: Cash drawer: “what I know; who I know; what I do.”<br />

Tax category<br />

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

A tax category object knows its category, its rate, and its effective date.<br />

Note: a combination of category and rate values might occur again and again, on<br />

various dates. This makes it a good candidate for an item-specific item pattern (although<br />

this is not pursued further in this chapter).<br />

open

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

Saved successfully!

Ooh no, something went wrong!