際際滷

際際滷Share a Scribd company logo
Apex and Design Pattern
Quick introduction on Apex and how we used some
design patterns to simplify our life
What is Apex?
- Salesforce OOP language
- Subset of Java
- No import (TrumpScript like), No package
- No Stdin, No Stdout
- Case insensitive
Model:
 DD ( L ) outside the language ( only point and click interface )
 DAO pattern
 Salesforce provides object and api to manipulate data in apex
View
Visual force page: Markup language ( JSF like )
Controller
Apex!!!
Idea behind Apex ( from my point of view )
Show me the code
Example:
Hello_World.cls
ViewModel_BillingItem.cls
Util_DML.cls
Our wonderful code
Strategy Pattern
- We define multiple algorithms
- Let client application decide
the algorithm to be used
based on the Context
Our wonderful code
Strategy Pattern
FlowCaseStrategy.cls ( Strategy Interface )
FlowCaseStrategyHeadless.cls ( Concrete Strategy A )
FlowCaseStrategyInteractive.cls ( Concrete Strategy B )
FlowRunner.cls ( Client Application )
Controller_FlowRunPage.cls ( Context )
EventHandler_Run_Flow.cls ( Context )
Our wonderful code
Abstract Factory
- Provide an interface for creating
families of related or dependent
objects without specifying their
concrete classes.
- The client software creates a
concrete implementation of the
abstract factory and then uses
the generic interface of the
factory to create the concrete
objects that are part of the
Our wonderful code
Abstract Factory
FlowDefinition.cls ( Abstract Factory )
FlowStep.cls ( Abstract Product )
Flow_ResetPassword.cls ( Concrete Factory )
FlowStep_ResetPassword_UpdateContactPass.cls ( Concrete Product )
InnerFlowRunner.cls ( Client )
FlowStepExecutor.cls ( Client )
Our wonderful code
Helper Pattern
- Also known as Utility Class
- Sometimes its considered an anti pattern
- Developer often forget to have that method in that helper class
- Some languages offer built-in functionality to introduce this pattern and solve
the forgetting issue
- C#  Extension Methods
- Scala  Companion Object
Our wonderful code
Util_Attachment.cls
Util_BillingItem.cls
Util_Case.cls
Util_Collection.cls
Util_Connection.cls
Util_Contract.cls
Util_Data.cls
Util_Database.cls
Util_DateTime.cls
Util_Departments.cls
Util_DML.cls
Util_Email.cls
Util_EventHandler.cls
Util_Exceptions.cls
Util_Flow.cls
Util_FlowContext.cls
Util_FlowState.cls
Util_IntegrationTest.cls
Util_Invoice.cls
Util_MeterReading.cls
Util_MockData.cls
Util_Notifications.cls
Util_Opportunity.cls
Util_Picklist.cls
Util_PrepareStagingEnvironment.cls
Util_Profiles.cls
Util_Reason.cls
Util_Signup.cls
Util_String.cls
Util_Test.cls
Util_Url.cls
Util_Validation.cls
Util_WebService.cls
Util_WrittenCare.cls
Daily Code Review
No more than 30 minutes
All team is up to date on the code
Continuous refactoring => Code highly maintainable
Very few dead code
Detect immediately classes poorly tested
Unify coding style. The code seems written by the same person
Happy coding with Apex :)

More Related Content

Apex and design pattern

Editor's Notes

  • #3: You cannot develop a complete feature on your machine and deploy on the cloud once it is finished.
  • #4: The design of the language follows the MVC pattern. They decided to keep the DDL outside of the. It must be made directly through the visual interface that salesforce provide. Internally salesforce provide something like a DAO in order to access and modify the data through the language. The view cannot be manipulated from apex as well but there is a markup language called visualforce page that allows the developer to do that. Eventually Apex is the language used to build all the controller functionalities. From the data validation to the flows implementation.
  • #11: (35 classes)