Domain class template

The implementation of the Domain class in this chapter utilizes the Financial Lightning Apex Enterprise Patterns library, which is open source and is included in the sample code of this chapter. In this library, the Apex base class, fflib_SObjectDomain, is provided to help implement the Domain layer pattern.

A basic template for a Domain class utilizing this base class is shown in the following code snippet:

public inherited sharing class Races extends fflib_SObjectDomain { 
  public Races(List<Race__c> races) { 
    super(races); 
  } 
 
  public class Constructor 
    implements fflib_SObjectDomain.IConstructable { 
    public fflib_SObjectDomain construct(
List<SObject>sObjectList) { return new Races(sObjectList); } } }

The first thing to note is that the constructor for this class takes a list of Race__c records, as per the guidelines described previously. The code implemented in a domain class is written with bulkification in mind. The base class constructor initializes the Records base class property.

The inner class, Constructor, is present to permit the dynamic creation of the Domain class in an Apex Trigger context. This is actually working around the lack of full reflection (the ability to reference the class constructor dynamically) in the Apex language. The name of this inner class must always be Constructor.

By extending the fflib_SObjectDomain class, the Domain class inherits properties and methods it can override to implement its own methods, such as the Records property, which provides access to the actual record data. There are virtual methods provided to make the implementation of the Apex Trigger easier, as well as some specialized events such as onValidate and onApplyDefaults. The following class overview illustrates some of the key methods in the base class that the Domain classes can override:

The fflib_SObjectDomain class is part of an open source library. As such, it is always receiving great contributions from the community. Be sure to check the latest version of this class for new methods and features!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.171.121