fflib-apex-common-samplecode
fflib-apex-common-samplecode copied to clipboard
Alternative instantiation for Services
Hi @ImJohnMDaniel
In these examples I see that thee are a number of different ways to create new instances for the several classes.
For domains there is a static method newInstance
on the implementation class Accounts
(e.g. static IAccounts newInstance(Set<Id> recordIdSet)
).
The service classes have their own separate class (e.g. OpportunitiesService
) with a static version of all the method signatures of its Interface.
There are also many developers I work with, who find this a bit cumbersome, a too big overhead and duplication of method signatures.
Would it be an idea to do something similar as we do with the domain?
How would you feel about calling service methods not via:
OpportunitiesService.applyDiscounts(ids, 10);
but via a lazy loading static property on the domain:
Opportunities.Service.applyDiscounts(ids, 10);
or exactly the same as the domain:
OpportunitiesService.newInstance().applyDiscounts(Ids, 10);
Have you had any discussions about this approach in the past? It would be nice if we can avoid that class with statics..
CC: @daveespo, @afawcett, @stohn777