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);
}
```
___