diff --git a/docs/README.asciidoc b/docs/README.asciidoc index 6791439..0fa7630 100644 --- a/docs/README.asciidoc +++ b/docs/README.asciidoc @@ -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 diff --git a/docs/fflib_ClassicDomainFactory.asciidoc b/docs/fflib_ClassicDomainFactory.asciidoc new file mode 100644 index 0000000..b931f63 --- /dev/null +++ b/docs/fflib_ClassicDomainFactory.asciidoc @@ -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 + +- <> + +Empty constructor creating an instance of the Domain Factory, +particularly used for classes extending fflib_ClassicDomainFactory. + +- <> + +Constructs a Domain factory, based on a map linking the ObjectType to the implementation class type. + +- <> + +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 recordIds)] + +Dynamically constructs an instance of a Domain class for the given record Ids +- link:fflib_IDomainFactory.asciidoc# recordIds, Schema.SObjectType sObjectType)] + +Dynamically constructs an instance of a Domain class for the given record Ids +- link:fflib_IDomainFactory.asciidoc#newInstance3[newInstance(List records)] + +Dynamically constructs an instance of the Domain class for the given records +- link:fflib_IDomainFactory.asciidoc#newInstance4[newInstance(List objects, Object objectType)] + +Dynamically constructs an instance of the Domain class for the given Objects +- link:fflib_IDomainFactory.asciidoc#newInstance5[newInstance(List 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 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 + { + Schema.Account.SObjectType => + AccountsSelector.class + } + ); + + public static final fflib_IDomainFactory Domain = + new fflib_ClassicDomainFactory( + Application.Selector, + new Map + { + 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 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 + { + Schema.Account.SObjectType => + AccountsSelector.class + } + ); + + public static final fflib_IDomainFactory Domain = + new fflib_ClassicDomainFactory( + Application.Selector, + new Map + { + Schema.Account.SObjectType => + Accounts.Constructor.class + } + ); +} +``` + +___ diff --git a/docs/fflib_DynamicDomainFactory.asciidoc b/docs/fflib_DynamicDomainFactory.asciidoc new file mode 100644 index 0000000..5910fe2 --- /dev/null +++ b/docs/fflib_DynamicDomainFactory.asciidoc @@ -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 + +- <> + + + +== 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 recordIds)] + +Dynamically constructs an instance of a Domain class for the given record Ids +- link:fflib_IDomainFactory.asciidoc# recordIds, Schema.SObjectType sObjectType)] + +Dynamically constructs an instance of a Domain class for the given record Ids +- link:fflib_IDomainFactory.asciidoc#newInstance3[newInstance(List records)] + +Dynamically constructs an instance of the Domain class for the given records +- link:fflib_IDomainFactory.asciidoc#newInstance4[newInstance(List objects, Object objectType)] + +Dynamically constructs an instance of the Domain class for the given Objects +- link:fflib_IDomainFactory.asciidoc#newInstance5[newInstance(List 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 **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); +} +``` + +___ \ No newline at end of file diff --git a/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicDomainFactory.cls b/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicDomainFactory.cls index fe1bbb1..d53cec1 100644 --- a/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicDomainFactory.cls +++ b/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicDomainFactory.cls @@ -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 diff --git a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicDomainFactory.cls b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicDomainFactory.cls index 5d025b2..3f23dcd 100644 --- a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicDomainFactory.cls +++ b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicDomainFactory.cls @@ -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 mockDomainByObjectType = new Map(); 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 bindings = resolver.byObject(objectType) - .byType(DOMAIN) + .byType(fflib_AppBindingType.Domain) .resolve(); if (bindings.isEmpty())