Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Application factories to be extended like fflib-apex-common #69

Conversation

chazwatkins
Copy link
Contributor

@chazwatkins chazwatkins commented Dec 6, 2022

It's currently impossible to extend the Application class factories to incorporate your own newInstance implementations. For example, Service.newInstanceByRecordType or Service.newInstanceByMyCustomFieldValue.

fflib-apex-common was updated to allow fflib_Application to be extended in December 2019. Closes #28

The Application factories can now be extended so each value stream in an org can have its own Application class with custom factories.

Ideally, I'd like to implement a core way to do newInstanceByRecordType using force-di, but this will suffice for now since it mirrors how fflib_Application works.

If there are any changes required, please let me know.

Change

Application

  • Made virtual class

Application.SelectorFactory

  • Made virtual class
  • Update constructor to protected
  • Update setMock to protected
  • Update all public and protected methods virtual

Application.UnitOfWorkFactory

  • Made virtual class
  • Update constructor to protected
  • Update setMock to protected
  • Update all public and protected methods virtual

Application.DomainFactory

  • Made virtual class
  • Update constructor to protected
  • Update setMock to protected
  • Update all public and protected methods virtual

Application.ServiceFactory

  • Made virtual class
  • Update constructor to protected
  • Update setMock to protected
  • Update all public and protected methods virtual

This change is Reviewable

@stohn777
Copy link
Collaborator

Hi @chazwatkins. If the intent is to virtualize Application's inner *Factory classes, then should their public methods be marked with the virtual modifier too, otherwise, one cannot override the existing functionality, if desired.

@chazwatkins
Copy link
Contributor Author

@stohn777 - Good call. I'll make the public methods virtual as well.

@chazwatkins
Copy link
Contributor Author

Hi @chazwatkins. If the intent is to virtualize Application's inner *Factory classes, then should their public methods be marked with the virtual modifier too, otherwise, one cannot override the existing functionality, if desired.

Hey @stohn777, I updated the public and protected methods to be virtual for extension.

@ImJohnMDaniel
Copy link
Collaborator

@chazwatkins I have been thinking about this PR for the past few weeks. I have a concern about the value of making Application and the subclasses virtual. My concern is that to make it virtual means that another class would extend (please forgive my 1st grade thought here - no offense is intended - just trying to draw picture). But in extending to another "application" class, wouldn't you be saying "all development in this org now must use this new FooBarApplication class everywhere instead of the established Application class? Part of the power of the FFLIB Apex Commons framework (and subsequently AT4DX) is that it centralizes every aspect of Service, Selector, Domain, and UOW object creation to an agreed upon set of four distinct application factories (not one). Every developer in the org knows to use the Application.Service, Application.Selector, Application.Domain, and Application.UnitOfWork factories. It is that "agreed upon convention" that increases the value of the patterns, and increases the adoption.

I guess my question becomes "What are some use cases that you believe are worth the disruption of changing the established pattern of using Application class?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Application class based on changes to fflib_Application
3 participants