Domain class template

The Domain class implementation in this chapter utilizes the FinancialForce.com 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 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.

Note

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 Apex Trigger behavior implementation 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:

Domain class template
..................Content has been hidden....................

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