In Chapter 4, Working with Form Logic and Frameworks, we wrote the ConVMSVehicleServiceTableType class. This had a method that determined whether or not the record can be edited. It used a CanEdit method, which in turn called a CanEditStatus method. There was nothing obviously wrong here, but what if our customer wanted to add a status? They could use Chain of Command, which is okay, but this also means we didn't design the solution to be extended in this way. There are two ways to structure the logic in this case:
- Use a switch statement on the status
- Write a class per status that is constructed based on the record's status
The latter option is used by SalesLineType. This is much simpler to read, especially when the code in each case is more than one line. It is also much easier to extend. The traditional way to write...