Summary

In this chapter, we have taken an in-depth look at how the platform executes Apex code and the different contexts from which it does so. We have also taken the time to understand how key concepts such as state and security are managed, in addition to highlighting some Apex governors and their respective scopes.

This has enabled us to identify some common needs, and using the principles of separation of concerns we can develop guidelines to be applied to layers in our business application code, making the Apex logic more reusable and accessible from different contexts as your application functionality and, indeed, the platform itself evolve.

As we progress further into practicing SOC, the Domain, Service, and Selector layer patterns will become a further layer of separation within our application business logic. We will continue to define the naming and coding guidelines as we progress through the next three chapters so that it becomes easier to maintain a good SOC for the existing developers and those just starting to work on the code.

If you have an existing code base and are wondering where to start with refactoring its code into the layers described in this chapter, my advice is to concentrate initially on forming your Service layer contract and refactoring as much true business logic code into it as possible. Make your execution context classes, such as controllers and Batch Apex classes (but not triggers initially), as thin as possible, leaving them to focus solely on their responsibilities, such as error handling. This will get some of your true business application logic, at least, contained below the Service layer, even if it might not be factored precisely how you would want it had you written it from scratch. After this, you can focus on expanding this to refactoring the trigger logic into Domain, then the query logic into separate selector classes, perhaps incrementally, as you revise areas of the application for enhancements.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.57.164