State (Chapter 22)

SOLUTION 22.1As the state machine shows, when the door is open, a click will take the door to the StayOpen state, and a second click will start the door closing.
SOLUTION 22.2Your code should look something like:
public void complete()
{
    if (state == OPENING)
    {
        setState(OPEN);
    }
    else if (state == CLOSING)
    {
        setState(CLOSED);
    }
}

public void timeout()
{
    setState(CLOSING);
}
SOLUTION 22.3The code for status() relies on the state's class name and will report, for example, the status of an open door as "DoorOpen", instead of "Open". You can, of course, trim off the "Door" prefix, if you like.
SOLUTION 22.4Your code should look something like:
 package com.oozinoz.carousel; public class DoorClosing extends DoorState { public ...

Get Design Patterns Java™ Workbook 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.