Classes
Classes and Instances | Persistent and Basic Classes | Encapsulation | Advanced Features |
This document introduces the class management performed in the Sage X3 supervisor and engine layers for version 7.0. It describes the main principles and provides links to additional detailed documents describing how they are used in a Sage X3 platform.
This is a major change from version 6, where the development partner used tables (called F class, which are a set of fields in a table), and masks (called M class, which are associated with the user interface). Version 7 still supports version 6 concepts in Classic mode, but version 7 development partners will use new concepts called classes that are usually linked to tables and representations that are linked to the UI definition.
A Sage X3 class is very similar to a class in an Object Oriented language. It describes a structure, which is shared by many objects called the instances of the class. It also describes behaviors that are shared by the instances. The following examples illustrate the concept.
The Customer class defines what is shared by all customers:
An instance of a class represents a specific object, for example customer C47 or C92. The instance contains the values of the properties defined by its class. For example, customer C47 may have the following values:
Customer C92 will have a different set of values for these properties.
Most classes will be persistent, which means that their instance data is stored and retrieved from the ERP database. If the class is simple, it can be mapped to a single table in the database. For example, an Address class can be mapped to a single ADDRESS table. Most classes are mapped to a set of tables with joins to express their relationships. For example, a Sales Order class can be mapped to a combination of SO Header, SO Line, and Address tables.
Classes can also be basic. In this case, the instance data is kept only in memory and disappears when the server process terminates. Basic classes are helpful when managing temporary data used by a computation.
The class logic (its methods and operations) should ensure that the instance data is always kept in a consistent state. For example, a Sales Order class should guarantee that the totals are always consistent with the line details after the order has been modified.
Classes are also used to organize the code and hide the details of the complex logic that may be needed to manage the objects. For example, the rules that update sales order totals when order lines are modified may be rather complex. These rules should be packaged inside the Sales Order class rather than spread accross various modules of the ERP system.
An entity is a set of records from different tables that have to be controlled and updated to keep the data consistent. A customer, General Ledger entry, product, and sales order are examples of an entity.
To use a class, you have to instantiate it, that is, allocate a block of memory for the values of the properties defined by the class.
Class properties may be:
A class can be used for easing complex data structure handling in a process, or it can be associated to a set of databases tables that stores the content of entities instances. In this case, the class is typed “persistent”. Other types of classes exist and are described later.
A class includes methods and operations. Some of them are predefined, while others can be added by the development partner. Both are procedures associated with a class that can be called from another program to operate on class instances. A method operates on a context or class instance, and thus is used only on an existing instance, while an operation can be used even when a context does not exist. The arguments passed to an operation must at least include the identification of the data set on which it operates.
Every property of a class has its standard methods and no other methods can be added. They allow a development partner to hide the technical implementation of the property and supply interface for its use. These methods are the following:
These three methods are called automatically by the Sage X3 engine when accessing or updating the properties. There is another method that is called by the supervisor in some dedicated cases:
Some automatic methods also exist on dedicated data types for managing translatable texts, but the scope in this document is only to describe the methods used on every class or property.
On the Sage X3 platform, using classes first needs to be declared in dedicated dictionaries. For more information, see Developer Guide Classes Dictionaries.
After declaring the classes, the Sage X3 script code can be written with classes, and benefit from the new instructions and functions described in Developer Guide Classes Script.
On persistent classes, standard methods have been implemented to ease the management of complex documents in the database. They are described in Developer Guide Classes Standard Methods.
Events provide the development partner the ability to add Sage X3 script code to manage standard events and to change their behavior. For more information, see Developer Guide Classes Events.