Chapter 9. Getting Control of Your Objects with the State and Proxy Patterns

<feature> <title>In This Chapter</title> <objective>

Using the State pattern

</objective>
<objective>

Letting states determine outcomes

</objective>
<objective>

Understanding the Proxy pattern

</objective>
<objective>

Using proxies to stand in for your objects

</objective>
<objective>

Connecting with proxies across the Internet

</objective>
</feature>

The CEO of Apartments-N-Stuff Inc. has reserved your services as a consultant and says, “We run huge, apartment-rental complexes all around the country. Our big problem is property managers — they cost too much. So we’re going to convert all our apartment complexes to use rental automats — robots that will accept rental applications and dispense keys — instead. We want new tenants to be able to submit their rental applications to an automat and, if they’re approved, get their keys from that automat.”

“Sounds nuts,” you say.

“Here’s the idea,” says the CEO. “Normally, the automat just sits around waiting for a prospective tenant to show up. When a tenant does submit an application, the automat checks it. If the application is approved, the automat should dispense keys to the tenant; otherwise, the automat should tell the tenant he was rejected and go back to waiting. Oh, and if the automat rents out an apartment, the automat should check if there are still any apartments left in the complex and not rent any more if there aren’t.”

The CEO watches as you scribble on a pad ...

Get Design Patterns For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.