|
A new and tremendously powerful feature was introduced in the Fall Release ’16. Now you can extend class instances, including adding state. This is available for any class in the system.
We already know we can extend class types. Which in essence allows us to introduce new methods that consumers of the class can benefit from. That was little more than compiler magic; now we got true class extension capabilities. |
Example
Suppose you want to extend the SysUserLogCleanup class. Out-of-the-box this class is deleting records from the SysUserLog table. Let’s imagine you want to archive these records to a different table before they are deleted.
The SysUserLogCleanup class is a runbase class, so you want to add a check mark to the dialog, get the result of that check box, act on it in the run method, pack/unpack etc. Here is how the state can be extended, and how to act on the dialog() and getFromDialog() methods.
[ExtensionOf(classStr(SysUserLogCleanup))] |
Please notice, to be a good citizen, I applied these practices:
- Prefixed the added members and methods. I used “mfp” as prefix. This is important to avoid name clashes with other extensions and future version of the class being extended.
- Hooked up post-method event handlers for the methods needed.
Other interesting aspects:
- This also work for forms.
- This way you can add instance methods to tables – but not state. Table’s don’t have a class declaration, so that is fair.
- This way of extending a class will not break the extended class’s encapsulation. I.e. you will not have access to any private fields or methods.
THIS POST IS PROVIDED AS-IS; AND CONFERS NO RIGHTS.