Skip to content

Commit f922242

Browse files
Merge pull request #334 from ctchipps/master
Application Class Extensibility
2 parents 8e1612a + f826eea commit f922242

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

sfdx-source/apex-common/main/classes/fflib_Application.cls

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public virtual class fflib_Application
3939
private List<SObjectType> m_objectTypes;
4040
private fflib_ISObjectUnitOfWork m_mockUow;
4141

42+
/**
43+
* Constructs a Unit Of Work factory
44+
**/
45+
public UnitOfWorkFactory() { }
46+
4247
/**
4348
* Constructs a Unit Of Work factory
4449
*
@@ -54,29 +59,27 @@ public virtual class fflib_Application
5459
* SObjectType list provided in the constructor, returns a Mock implementation
5560
* if set via the setMock method
5661
**/
57-
public fflib_ISObjectUnitOfWork newInstance()
62+
public virtual fflib_ISObjectUnitOfWork newInstance()
5863
{
5964
// Mock?
6065
if(m_mockUow!=null)
6166
return m_mockUow;
6267
return new fflib_SObjectUnitOfWork(m_objectTypes);
6368
}
6469

65-
6670
/**
6771
* Returns a new fflib_SObjectUnitOfWork configured with the
6872
* SObjectType list provided in the constructor, returns a Mock implementation
6973
* if set via the setMock method
7074
**/
71-
public fflib_ISObjectUnitOfWork newInstance(fflib_SObjectUnitOfWork.IDML dml)
75+
public virtual fflib_ISObjectUnitOfWork newInstance(fflib_SObjectUnitOfWork.IDML dml)
7276
{
7377
// Mock?
7478
if(m_mockUow!=null)
7579
return m_mockUow;
7680
return new fflib_SObjectUnitOfWork(m_objectTypes, dml);
7781
}
7882

79-
8083
/**
8184
* Returns a new fflib_SObjectUnitOfWork configured with the
8285
* SObjectType list specified, returns a Mock implementation
@@ -85,7 +88,7 @@ public virtual class fflib_Application
8588
* @remark If mock is set, the list of SObjectType in the mock could be different
8689
* then the list of SObjectType specified in this method call
8790
**/
88-
public fflib_ISObjectUnitOfWork newInstance(List<SObjectType> objectTypes)
91+
public virtual fflib_ISObjectUnitOfWork newInstance(List<SObjectType> objectTypes)
8992
{
9093
// Mock?
9194
if(m_mockUow!=null)
@@ -101,17 +104,16 @@ public virtual class fflib_Application
101104
* @remark If mock is set, the list of SObjectType in the mock could be different
102105
* then the list of SObjectType specified in this method call
103106
**/
104-
public fflib_ISObjectUnitOfWork newInstance(List<SObjectType> objectTypes, fflib_SObjectUnitOfWork.IDML dml)
107+
public virtual fflib_ISObjectUnitOfWork newInstance(List<SObjectType> objectTypes, fflib_SObjectUnitOfWork.IDML dml)
105108
{
106109
// Mock?
107110
if(m_mockUow!=null)
108111
return m_mockUow;
109112
return new fflib_SObjectUnitOfWork(objectTypes, dml);
110113
}
111114

112-
113115
@TestVisible
114-
private void setMock(fflib_ISObjectUnitOfWork mockUow)
116+
protected virtual void setMock(fflib_ISObjectUnitOfWork mockUow)
115117
{
116118
m_mockUow = mockUow;
117119
}
@@ -126,6 +128,11 @@ public virtual class fflib_Application
126128

127129
protected Map<Type, Object> m_serviceInterfaceTypeByMockService;
128130

131+
/**
132+
* Constructs a simple Service Factory
133+
**/
134+
public ServiceFactory() { }
135+
129136
/**
130137
* Constructs a simple Service Factory,
131138
* using a Map of Apex Interfaces to Apex Classes implementing the interface
@@ -162,7 +169,7 @@ public virtual class fflib_Application
162169
}
163170

164171
@TestVisible
165-
private virtual void setMock(Type serviceInterfaceType, Object serviceImpl)
172+
protected virtual void setMock(Type serviceInterfaceType, Object serviceImpl)
166173
{
167174
m_serviceInterfaceTypeByMockService.put(serviceInterfaceType, serviceImpl);
168175
}
@@ -176,6 +183,11 @@ public virtual class fflib_Application
176183
protected Map<SObjectType, Type> m_sObjectBySelectorType;
177184
protected Map<SObjectType, fflib_ISObjectSelector> m_sObjectByMockSelector;
178185

186+
/**
187+
* Constructs a simple Selector Factory
188+
**/
189+
public SelectorFactory() { }
190+
179191
/**
180192
* Consturcts a Selector Factory linking SObjectType's with Apex Classes implement the fflib_ISObjectSelector interface
181193
* Note that the factory does not check the given Apex Classes implement the interface
@@ -218,7 +230,7 @@ public virtual class fflib_Application
218230
* @param recordIds The SObject record Ids, must be all the same SObjectType
219231
* @exception Is thrown if the record Ids are not all the same or the SObjectType is not registered
220232
**/
221-
public List<SObject> selectById(Set<Id> recordIds)
233+
public virtual List<SObject> selectById(Set<Id> recordIds)
222234
{
223235
// No point creating an empty Domain class, nor can we determine the SObjectType anyway
224236
if(recordIds==null || recordIds.size()==0)
@@ -246,7 +258,7 @@ public virtual class fflib_Application
246258
* @param relatedRecords used to extract the related record Ids, e.g. Opportunity records
247259
* @param relationshipField field in the passed records that contains the relationship records to query, e.g. Opportunity.AccountId
248260
**/
249-
public List<SObject> selectByRelationship(List<SObject> relatedRecords, SObjectField relationshipField)
261+
public virtual List<SObject> selectByRelationship(List<SObject> relatedRecords, SObjectField relationshipField)
250262
{
251263
Set<Id> relatedIds = new Set<Id>();
252264
for(SObject relatedRecord : relatedRecords)
@@ -259,7 +271,7 @@ public virtual class fflib_Application
259271
}
260272

261273
@TestVisible
262-
private virtual void setMock(fflib_ISObjectSelector selectorInstance)
274+
protected virtual void setMock(fflib_ISObjectSelector selectorInstance)
263275
{
264276
m_sObjectByMockSelector.put(selectorInstance.sObjectType(), selectorInstance);
265277
}
@@ -276,6 +288,11 @@ public virtual class fflib_Application
276288

277289
protected Map<Object, fflib_IDomain> mockDomainByObject;
278290

291+
/**
292+
* Constructs a Domain factory
293+
**/
294+
public DomainFactory() { }
295+
279296
/**
280297
* Constructs a Domain factory, using an instance of the Selector Factory
281298
* and a map of Apex classes implementing fflib_ISObjectDomain by SObjectType
@@ -396,18 +413,18 @@ public virtual class fflib_Application
396413
}
397414

398415
@TestVisible
399-
private virtual void setMock(fflib_ISObjectDomain mockDomain)
416+
protected virtual void setMock(fflib_ISObjectDomain mockDomain)
400417
{
401418
mockDomainByObject.put((Object) mockDomain.sObjectType(), (fflib_IDomain) mockDomain);
402419
}
403420

404421
@TestVisible
405-
private virtual void setMock(fflib_IDomain mockDomain)
422+
protected virtual void setMock(fflib_IDomain mockDomain)
406423
{
407424
mockDomainByObject.put(mockDomain.getType(), mockDomain);
408425
}
409426

410-
private Map<Object, Type> getConstructorTypeByObject(Map<SObjectType, Type> constructorTypeBySObjectType)
427+
protected virtual Map<Object, Type> getConstructorTypeByObject(Map<SObjectType, Type> constructorTypeBySObjectType)
411428
{
412429
Map<Object, Type> result = new Map<Object, Type>();
413430
for (SObjectType sObjectType : constructorTypeBySObjectType.keySet())

0 commit comments

Comments
 (0)