Business Objects
Business objects implement the software's business logic. They are responsible for handling data objects (constructing, loading, saving, deleting) and any other business logic related with the business module. For every data object, there is a business object that handles it. Business objects do not implement any process flows, but offer services to the Controller layer (UI, API, Process)
In CRM.COM Software, we implement the business object classes using EJBs (Enterprise Java Beans) J2EE server-side components, and more specifically we use Stateless Session Beans. More information about EJBs can be found here.
Creating the Business Object Classes
The first thing to do is to create an EJB that will handle our business objects. In order to create our class we must first decide the name of the package to place it in. Based on the business structure, the respective packages should be created. Based on CRM.COM naming conventions, all business objects are stored in the com.crm.businessobject package. Based on the module we are implementing, further packages are then created in here.
In this case, we will create the package com.crm.businessobject.accounts that will contain the module's business object classes, and create the CRMBOBankBean.java business object class.
Note that on EJB creation, we also specify the super class of the class we are creating, depending on the business logic of our class. In this case we select the com.crm.businessobject.CRMBO as the super class.
To implement the basic business logic in our class, we will need to create the following methods:
This method creates a new instance of the data object. In this method we add any business logic required when creating a new entity. The mainDTO parameter is not null in case the data object to be created should be related with another data object.
This method saves the data objects to the database. In this method we add any business logic required to be executed when saving an entity.
This method deletes the data objects. In this method we add any business logic required to be executed when deleting an entity. Note that records are not physically deleted but marked as deleted.
This method validates the data objects before saving to the database. Any validations that should be done before saving the data object to the database should be performed in this method.
This method validates the data objects before saving to the database as deleted. Any validations that should be done before deleting the data object should be performed in this method.
This method returns the class of the data object that is handled by the specific business object. It is used mainly to construct the HQL (Hibernate Query Language) dynamically.
This method returns a list of the associated data objects that should be loaded by default when loading a data object. It is called by abstract functionality to load the data objects associated data objects.
This method returns a sequence number that is set on the data object in case it has a number property. It is called by abstract functionality to set the data object's number when saving the data object.
This method returns a list of the data object's mandatory fields (fields that should be always set). This method is called by abstract functionality to validate that all mandatory fields are set.
To start implementing the controller layer, go to Developing the Controller layer