...

/

Exercise: Warehouse Item

Exercise: Warehouse Item

Practice how to implement a warehouse management program using the State pattern.

Problem statement

Imagine we’re working on a warehouse management program. Our next task is to create a class to model a warehouse item and help track it. Such a WarehouseItem class has a constructor, which accepts an id and the initial state of the item (which can be one of arriving, stored, or delivered). It has three public methods: 

  • store(locationId) moves the item into the stored state and records locationId where it’s stored. 

  • deliver(address) changes the state of the item to delivered, sets the delivery ...