Exercise: Warehouse Item
Explore how to apply the State design pattern to create a WarehouseItem class that manages item states such as arriving, stored, and delivered. Learn to implement state-specific behavior and enforce state transition rules, enhancing your ability to handle complex behavioral patterns in Node.js design.
We'll cover the following...
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 thestoredstate and recordslocationIdwhere it’s stored.deliver(address)changes the state of the item to ...