Technically, form handler classes are not required as all code can be added directly to a form. The problem with this is that, as form logic gets more logic, it becomes harder to read as the purpose of each method becomes less obvious and less easy to maintain as the amount of code increases. Code placed directly on a form is usually much harder to use by third parties and the code is not reusable.
For this reason, we would usually create a form handler class to handle user interface logic on order entry style forms. These forms usually need a create form in order to make order creation easier. The form handler will act as a way to pass data between the main order entry form and the create form.
Form handlers were used to handle number sequences, but the pattern has changed now as number sequence handling is more logically handled on the form, or on a table handler class. This means that a form handler has two main functions:
- To control the user interface in terms of visibility, allowing edits, and adjusting labels
- To act as a mechanism that allows communication from the create form and the main entry form
The purpose of our form handler class will be to control whether the data can be edited on our ConVMSVehicleServiceTable form based on the service order status. We will not place any business logic on this class, only form handling code. The rules of whether we can edit or not will be written onto the table, which again could be a table handler class, should this be required.