I have been thinking and reading about Apex Enterprise patterns and how I can make my own code more reusable.


This got me thinking about naming conventions. I am curious if anyone has naming conventions they use to indicate that a class in part of the service layer, selector layer etc...

| improve this question | | | | |

Here is what I use (I follow the fflib apex-common examples pattern plus the examples in the Fawcett book which are about custom objects Driver__c, Contestant__c, and Race__c).

Standard object like Account or Custom Object w/o underscore like Foo__c

Domain: Accounts.cls
Service: AccountsService.cls and AccountsServiceImpl.cls
Selector: AccountsSelector.cls

Domain: Foos.cls
Service: FoosService.cls and FoosServiceImpl.cls
Selector: FoosSelector.cls

Custom object w/ underscore like Async_Request__c

Domain: AsyncRequests.cls
Service: AsyncRequestsService.cls and AsyncRequestsServiceImpl.cls
Selector: AsyncRequestsSelector.cls

Note use of plurals everywhere as these layers are supposed to always work with collections

Specialized service unrelated to any domain SObject

Service: MyService.cls and MyServiceImpl.cls

Note could be plurally-named but depends on context

| improve this answer | | | | |

Note that I am not a user of https://github.com/financialforcedev/fflib-apex-common so this is an outsider's opinion.

If you want to include pattern names in class names then making the pattern name a suffix seems a good way to go so the domain name (or SObject name) comes first meaning classes are grouped by that domain name (or SObject name). (Limited) examples of that here: https://github.com/financialforcedev/fflib-apex-common-samplecode/tree/master/fflib-sample-code/src/classes such as AccountsSelector and InvoicingService.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.