Best practice data classes
The purpose of this document is to provide best practice guidelines when developing in Version 7 native mode.
The following rules are considered ‘best practice’ when developing a data class:
Class name
Be consistent. Use the same code throughout the development process. A data class should have the same code as the main data table. For example, if the data table code is "MYCODE", use "MYCODE" for the data class code.
Class property names
Be consistent. Use the same name for class properties as used for the data table properties. This allows the trans-class between table and class and vice versa.
Even if it’s not technically mandatory, assign a single code to a property in the data table and the data class. It is easier to understand and to maintain.
Class information
A class implements standard Create, Read, Update, and Delete (CRUD) methods and custom methods on data. It must only contain data that is relevant to these methods.
Parent / Child classes
- Keep your data model simple.
- If there is a '1 : many' relationship, you should have one persistent parent class and one basic child class.
- A child class can only have one parent class.
- If there is a '1 : 1' relationship between a parent and a child class you do not need to create a basic class. A child class can be added to the parent class.
- If a child class can be created on its own, include this child class as a reference not as a child class.
Developing a class for mobile and desktop
- Only add to the class what is really needed. This helps avoid issues with mobile.
- You are always connected to the server when using the desktop. When using mobile, you are only occasionally connected to the server. This impacts what can be included in a class.
- You should avoid adding data management actions in your class, (for example, PROPAGATE, CONTROL, and so forth). Data management actions should be added to the representation class.
Unit tests
- Create a unit test (AXUNIT) for each data class.
- It is recommended that an AXUNIT test is created and run before creating your representation class.
- The AXUNIT test should test all the standard (CRUD) and custom methods enabled for the class.
Data class best practice summary
- You must use the same code for a data table and the data class.
- You must assign a single code to a property in the data table and the data class.
- You must use the same name for class properties as used for the data table properties.
- You must use the default codes for a class process.
- The data class must only contain data that is relevant to methods implemented.
- Keep your data model simple.
- Develop the data class for mobile and desktop.
- Develop AXUNIT tests for your class.