Chapter 1: X++ Unit Test Framework
Chapter 2: Working with Data
Chapter 3: Classes
Chapter 4: Forms
Chapter 5: Visual Studio Integration
Chapter 6: Workflow
Lesson 5 : Placement of Code
Placement of Code
The form offers many opportunities to place code on events. Try to minimize the X++ code in forms for the following reasons:
- Forms do not support inheritance. You cannot share logic implemented in a form with other application objects.
- The X++ code implemented in forms is always executed on the client. This means that you cannot tune an application by specifying where to execute the code.
To program system-wide logic, which is closely related to a record, put the logic in object methods on the table. The table which inherits from the kernel class xRecord has many events you can override and supplement with logic.
If designing logic which is more related to the function of the form, than the individual records in the data source, consider making a class which supports the form. If the form can work with different variations of functions or data, this approach supports using polymorphism.
If putting the X++ code in the form, avoid programming on the design and put your logic on the data source. Many events on the design are dependent on exactly how the user navigates the form. Code on the form controls does not take the possibility of the user modifying the contents of the form into account.