4

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

https://andyinthecloud.com/author/andrewmarkfawcett/

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...

2 Answers 2

7

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

4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .