Add method reference for Classic and Dynamic domain factories

This commit is contained in:
Wim Velzeboer
2021-07-08 10:16:00 +01:00
parent 372fa3f832
commit 8185e3416c
5 changed files with 289 additions and 13 deletions
+2 -2
View File
@@ -16,7 +16,7 @@
- fflib_IServiceFactory
- fflib_IUnitOfWorkFactory
* *Classic*
- fflib_ClassicDomainFactory
- link:fflib_ClassicDomainFactory.asciidoc[fflib_ClassicDomainFactory]
- fflib_ClassicSelectorFactory
- fflib_ClassicServiceFactory
- fflib_ClassicTriggerHandlerFactory
@@ -36,7 +36,7 @@
** fflib_AppBindingsSelector
** fflib_AppBindingType
** fflib_DynamicAppFactory
** fflib_DynamicDomainFactory
** link:fflib_DynamicDomainFactory.asciidoc[fflib_DynamicDomainFactory]
** fflib_DynamicSelectorFactory
** fflib_DynamicServiceFactory
** fflib_SharingMode
+179
View File
@@ -0,0 +1,179 @@
= fflib_ClassicDomainFactory Class
:Author: Wilhelmus G.J. Velzeboer
:Email: wim@velzeboer.nl
:Date: 2021
:Revision: version 1
Domain Factory for creating instances of Domain classes using a static map for
linking the SObjectType to its Domain Constructor implementation class.
This class is extended from
link:https://github.com/apex-enterprise-patterns/fflib-apex-common/blob/master/sfdx-source/apex-common/main/classes/fflib_Application.cls[fflib_Application.DomainFactory]
and implements the
link:fflib_IDomainFactory.asciidoc[fflib_IDomainFactory]
interface class.
== Constructor Methods
- <<constructor0, constructor: ()>> +
Empty constructor creating an instance of the Domain Factory,
particularly used for classes extending fflib_ClassicDomainFactory.
- <<constructor1, constructor: (selectorFactory, constructorTypeByObject) >> +
Constructs a Domain factory, based on a map linking the ObjectType to the implementation class type.
- <<constructor2, constructor: (selectorFactory, sObjectByDomainConstructorType) >> +
Constructs a Domain factory, based on a map linking the SObjectType to the implementation class type. +
**Use only for backwards compatibility**.
== Methods
This implementation of
link:fflib_IDomainFactory.asciidoc[fflib_IDomainFactory]
Does not add any new public or protected methods other than the following methods
which are defined in the interface
link:fflib_IDomainFactory.asciidoc[fflib_IDomainFactory].
- link:fflib_IDomainFactory.asciidoc#newInstance1[newInstance(Set<Id> recordIds)] +
Dynamically constructs an instance of a Domain class for the given record Ids
- link:fflib_IDomainFactory.asciidoc#<newInstance2[newInstance(Set<Id> recordIds, Schema.SObjectType sObjectType)] +
Dynamically constructs an instance of a Domain class for the given record Ids
- link:fflib_IDomainFactory.asciidoc#newInstance3[newInstance(List<SObject> records)] +
Dynamically constructs an instance of the Domain class for the given records
- link:fflib_IDomainFactory.asciidoc#newInstance4[newInstance(List<Object> objects, Object objectType)] +
Dynamically constructs an instance of the Domain class for the given Objects
- link:fflib_IDomainFactory.asciidoc#newInstance5[newInstance(List<SObject> records, Schema.SObjectType sObjectType)] +
Dynamically constructs an instance of the Domain class for the given records
- link:fflib_IDomainFactory.asciidoc#setMock1[setMock(fflib_ISObjectDomain mockDomain)] +
- link:fflib_IDomainFactory.asciidoc#setMock2[setMock(Schema.SObjectType sObjectType, fflib_ISObjectDomain mockDomain)] +
Registers a mock implementation in the Factory for the provided sObjectType
- link:fflib_IDomainFactory.asciidoc#setMock3[setMock(fflib_IDomain mockDomain)] +
Registers a mock in the Factory by providing a mock instance of a domain
- link:fflib_IDomainFactory.asciidoc#setMock4[setMock(Object domainType, fflib_IDomain mockDomain)] +
Registers a mock implementation in the Factory for the provided sObjectType
[[constructor0]]
=== fflib_ClassicDomainFactory()
Empty constructor creating an instance of the Domain Factory,
particularly used for classes extending fflib_ClassicDomainFactory.
==== _Signature_
```java
public fflib_ClassicDomainFactory() {}
```
___
[[constructor1]]
=== fflib_ClassicDomainFactory(selectorFactory, constructorTypeByObject)
Constructs a Domain factory, based on a map linking the ObjectType to the
implementation class type.
CAUTION: This will not check if the Apex classes actually implements the
interfaces since this is not possible in the Apex runtime at present
==== _Signature_
```java
public fflib_ClassicDomainFactory(
fflib_ISelectorFactory selectorFactory,
Map<Object, Type> constructorTypeByObject)
```
==== _Parameters_
_**selectorFactory**_ +
A reference to the Selector Factory instance,
which is an implementation of
link:fflib_ISelectorFactory.asciidoc[fflib_ISelectorFactory].
_**constructorTypeByObject**_ +
Map of Domain classes constructor by Object Type.
The Domain class constructor needs to be an implementation of
link:https://github.com/apex-enterprise-patterns/fflib-apex-common/blob/master/sfdx-source/apex-common/main/classes/fflib_IDomainConstructor.cls[fflib_IDomainConstructor]
==== _Example_
```java
public class Application
{
public static final fflib_ISelectorFactory Selector =
new fflib_ClassicSelectorFactory(
new Map<SObjectType, Type>
{
Schema.Account.SObjectType =>
AccountsSelector.class
}
);
public static final fflib_IDomainFactory Domain =
new fflib_ClassicDomainFactory(
Application.Selector,
new Map<Object, Type>
{
Schema.Account.SObjectType =>
Accounts.Constructor.class
}
);
}
```
___
[[constructor2]]
=== fflib_ClassicDomainFactory(selectorFactory, constructorTypeByObject)
Constructs a Domain factory, using an instance of the Selector Factory
and a map of Apex classes implementing fflib_ISObjectDomain by SObjectType
NOTE: Use only for backwards compatibility!
CAUTION: This will not check if the Apex classes actually implements the
interfaces since this is not possible in the Apex runtime at present
==== _Signature_
```java
public fflib_ClassicDomainFactory(fflib_ISelectorFactory selectorFactory,
Map<SObjectType, Type> sObjectByDomainConstructorType)
```
==== _Parameters_
_**selectorFactory**_ +
A reference to the Selector Factory instance,
which is an implementation of
link:fflib_ISelectorFactory.asciidoc[fflib_ISelectorFactory].
_**constructorTypeByObject**_ +
Map of Domain classes constructor by SObjectType.
The Domain class constructor needs to be an implementation of
link:https://github.com/apex-enterprise-patterns/fflib-apex-common/blob/master/sfdx-source/apex-common/main/classes/fflib_IDomainConstructor.cls[fflib_IDomainConstructor]
==== _Example_
```java
public class Application
{
public static final fflib_ISelectorFactory Selector =
new fflib_ClassicSelectorFactory(
new Map<SObjectType, Type>
{
Schema.Account.SObjectType =>
AccountsSelector.class
}
);
public static final fflib_IDomainFactory Domain =
new fflib_ClassicDomainFactory(
Application.Selector,
new Map<SObjectType, Type>
{
Schema.Account.SObjectType =>
Accounts.Constructor.class
}
);
}
```
___
+90
View File
@@ -0,0 +1,90 @@
= fflib_DynamicDomainFactory Class
:Author: Wilhelmus G.J. Velzeboer
:Email: wim@velzeboer.nl
:Date: 2021
:Revision: version 1
Domain Factory for creating instances of Domain classes using a resolver
to dynamically link an Object type to its Domain Constructor implementation class
This class is extended from
fflib_DynamicAppFactory
and implements the
link:fflib_IDomainFactory.asciidoc[fflib_IDomainFactory]
interface class.
== Constructor Methods
- <<constructor0, constructor: (resolver, selectorFactory)>> +
== Methods
This implementation of
link:fflib_IDomainFactory.asciidoc[fflib_IDomainFactory]
Does not add any new public or protected methods other than the following methods
which are defined in the interface
link:fflib_IDomainFactory.asciidoc[fflib_IDomainFactory].
- link:fflib_IDomainFactory.asciidoc#newInstance1[newInstance(Set<Id> recordIds)] +
Dynamically constructs an instance of a Domain class for the given record Ids
- link:fflib_IDomainFactory.asciidoc#<newInstance2[newInstance(Set<Id> recordIds, Schema.SObjectType sObjectType)] +
Dynamically constructs an instance of a Domain class for the given record Ids
- link:fflib_IDomainFactory.asciidoc#newInstance3[newInstance(List<SObject> records)] +
Dynamically constructs an instance of the Domain class for the given records
- link:fflib_IDomainFactory.asciidoc#newInstance4[newInstance(List<Object> objects, Object objectType)] +
Dynamically constructs an instance of the Domain class for the given Objects
- link:fflib_IDomainFactory.asciidoc#newInstance5[newInstance(List<SObject> records, Schema.SObjectType sObjectType)] +
Dynamically constructs an instance of the Domain class for the given records
- link:fflib_IDomainFactory.asciidoc#setMock1[setMock(fflib_ISObjectDomain mockDomain)] +
- link:fflib_IDomainFactory.asciidoc#setMock2[setMock(Schema.SObjectType sObjectType, fflib_ISObjectDomain mockDomain)] +
Registers a mock implementation in the Factory for the provided sObjectType
- link:fflib_IDomainFactory.asciidoc#setMock3[setMock(fflib_IDomain mockDomain)] +
Registers a mock in the Factory by providing a mock instance of a domain
- link:fflib_IDomainFactory.asciidoc#setMock4[setMock(Object domainType, fflib_IDomain mockDomain)] +
Registers a mock implementation in the Factory for the provided sObjectType
== Protected Variables
- Map<Object, fflib_IDomain> **mockDomainByObjectType** +
A map linking the ObjectType to a mock implementation of the domain.
- fflib_ISelectorFactory **selectorFactory** +
Holds the reference to the selector factory instance.
---
[[constructor0]]
=== fflib_DynamicDomainFactory(resolver, selectorFactory)
==== _Signature_
```java
public fflib_DynamicDomainFactory(fflib_IAppBindingResolver resolver, fflib_ISelectorFactory selectorFactory)
```
==== _Parameters_
_**resolver**_ +
A reference to the resolve instance,
which dynamically links an Object type to its Domain Constructor implementation class
_**selectorFactory**_ +
A reference to the selector factory instance,
to query records when a domain is created via record Ids.
==== _Example_
```java
public class Application
{
private static fflib_IAppBindingResolver bindingResolver =
new fflib_AppBindingResolver();
public static final fflib_ISelectorFactory Selector =
new fflib_DynamicSelectorFactory(bindingResolver);
public static final fflib_IDomainFactory Domain =
new fflib_DynamicDomainFactory(bindingResolver, Selector);
}
```
___
@@ -1,6 +1,7 @@
/**
* File Name: fflib_ClassicDomainFactory
* @description
* @description Domain Factory for creating instances of Domain classes
* using a static map for linking the SObjectType to its Domain Constructor implementation class
*
* @author architect ir. Wilhelmus G.J. Velzeboer
*
@@ -40,13 +41,13 @@ public virtual class fflib_ClassicDomainFactory
public fflib_ClassicDomainFactory() {}
/**
* Constructs a Domain factory, using an instance of the Selector Factory
* and a map of Apex classes implementing fflib_ISObjectDomain by SObjectType
* Note this will not check the Apex classes provided actually implement the interfaces
* since this is not possible in the Apex runtime at present
* Constructs a Domain factory, based on a map linking the ObjectType to the
* implementation class type.
* Note: this will not check if the Apex classes actually implements the
* interfaces since this is not possible in the Apex runtime at present
*
* @param selectorFactory , e.g. Application.Selector
* @param constructorTypeByObject Map of Domain classes by ObjectType
* @param selectorFactory, A reference to the Selector Factory instance, an instance of fflib_ISelectorFactory
* @param constructorTypeByObject Map of Domain classes by Object Type
**/
public fflib_ClassicDomainFactory(
fflib_ISelectorFactory selectorFactory,
@@ -62,6 +63,7 @@ public virtual class fflib_ClassicDomainFactory
* and a map of Apex classes implementing fflib_ISObjectDomain by SObjectType
* Note this will not check the Apex classes provided actually implement the interfaces
* since this is not possible in the Apex runtime at present
* Use only for backwards compatibility.
*
* @param selectorFactory , e.g. Application.Selector
* @param sObjectByDomainConstructorType Map of Apex classes by SObjectType
@@ -1,6 +1,7 @@
/**
* File Name: fflib_DynamicDomainFactory
* @description
* @description Domain Factory for creating instances of Domain classes
* using a resolver to dynamically link an Object type to its Domain Constructor implementation class
*
* @author architect ir. Wilhelmus G.J. Velzeboer
*
@@ -32,12 +33,16 @@ public virtual class fflib_DynamicDomainFactory
extends fflib_DynamicAppFactory
implements fflib_IDomainFactory
{
public static final fflib_AppBindingType DOMAIN = fflib_AppBindingType.Domain;
protected Map<Object, fflib_IDomain> mockDomainByObjectType = new Map<Object, fflib_IDomain>();
protected fflib_ISelectorFactory selectorFactory;
/**
* Class constructor
*
* @param resolver A reference to the resolve instance
* @param selectorFactory A reference to the selector factory instance
*/
public fflib_DynamicDomainFactory(fflib_IAppBindingResolver resolver, fflib_ISelectorFactory selectorFactory)
{
this.resolver = resolver;
@@ -72,7 +77,7 @@ public virtual class fflib_DynamicDomainFactory
if (hasMock(objectType)) return (fflib_IDomain) getMock(objectType);
List<fflib_IAppBinding> bindings = resolver.byObject(objectType)
.byType(DOMAIN)
.byType(fflib_AppBindingType.Domain)
.resolve();
if (bindings.isEmpty())