Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Making States Constant

Suppose that you decide to move the state constants to a _DoorConstants interface. For this approach to work, you have to eliminate the Door instance variable from the DoorState class. You can drop this variable by changing the click(), complete(), and timeout() transition methods in the DoorState class to require a Door object as an input parameter. In this design, a Door object that receives, for example, a click() method from the carousel forwards this call as state.click(this).

Challenge 22.5

Complete the class diagram in Figure 22.4 to show a design that moves the door states to an interface.

Figure 22.4Figure 22.4 Complete this diagram to shows door states as constants defined by the DoorConstants interface.

A solution appears on page 416.

  • + Share This
  • 🔖 Save To Your Account