Best Practices - Data Classes
The purpose of this document is to provide best practices when developing a data class in native mode.
Class name
Make sure you use the same code consistently throughout the development process. A data class should have the same code as the main data table.
Example: If the data table code is "MYCODE", use "MYCODE" for the data class code.
Class property names
- Make sure you use the same name consistently for class properties (the one used in the data table properties). This allows trans-class between table and class.
- Make sure you assign a single code to a property in the data table and in the data class. This is not mandatory but it makes things easier to understand and maintain.
Class information
A class implements standard Create, Read, Update, and Delete (CRUD) methods, as well as custom methods. Make sure it only contains data that is relevant to these methods.
Parent / Child classes
- Keep your data model simple.
- In the case of "one-to-many" relationships, make sure you have a persistent parent class and a basic child class.
- Make sure each child class only has one parent class.
- In the case of "one-to-one" relationships between a parent and a child class, you do not have to create a basic class. You can directly add a child class to the parent class.
- If a child class can be created on its own, make sure you include it as a reference, and not as a child class.
Developing a class for mobile and desktop
- Only add data needed by the class. This helps avoid issues with mobile.
- Be careful what you include in the class, because while you are always connected to the server when using the desktop, it is more occasional when using mobile.
- Try to avoid adding data management actions in your class (such as PROPAGATE or CONTROL). Such actions should be added to the representation class.
Unit tests
- Create a unit test (AXUNIT) for each data class. Make sure you create and run it before creating your representation class.
- Use the AXUNIT test to test all standard (CRUD) and custom methods enabled for the class.