Playing with data structures and algorithms for complex problems is always fun. Let’s see how we can implement those algorithms in Salesforce using Apex Design patterns. Object Oriented Programming is key for a design pattern. We will learn the basics of Object Oriented Programming and understand when we should use a Design pattern, Technical deep dive into different patterns, and some real examples of Apex Design patterns.
What are Design Patterns?
Design patterns are class structures that solve many of the commonly occurring issues in software. If algorithms are like baking instructions, then design patterns are like blueprints. They allow us to share a similar vocabulary of abstraction above that of implementation.
Type of Apex Design Patterns
Here are patterns we will be discussing in the blog post:
Singleton Design pattern in Apex
The Singleton pattern is a creational pattern – it helps you to instantiate objects in a particular way. It allows for the existence of only one instance of an object, but everyone has global access to that object. Singletons can help improve performance and reduce memory footprint.
The builder pattern is a creational pattern – it helps you to instantiate objects in a particular way. This pattern allows you to construct complicated objects step by step. Builders help to populate immutable private variables at construction without a multiple position based constructor arguments
Strategy Pattern (aka the policy pattern)
The strategy pattern is a behavioral pattern that helps you control dynamic application flow. This pattern allows us to define a family of algorithms through multiple classes which implement an interface. The choice of which implementation to use is determined at runtime.
A command pattern is a data-driven design pattern and falls under the behavioral pattern category. A request is wrapped under an object as a command and passed to the invoker object. Invoker object looks for the appropriate object which can handle this command and passes the command to the corresponding object which executes the command
Simplifying the execution of classes with complex interfaces (e.g. web service callouts)
Factory pattern is one of the most used design patterns in Java. This type of design pattern comes under creational pattern as this pattern provides one of the best ways to create an object.
Apex Design Patterns Training
There are different design patterns available but in this Apex Design patterns training will cover 4 design patterns with object-oriented Programming language brush up on vocabulary
- Object Oriented Programming
- Singleton: There can only be one – [ Sept 15, 2022, 9:00 AM EST ]
- Strategy: Make a gametime call – [ TBD after Dreamforce ]
- Builder: Construct complex objects [ TBD after Dreamforce ]
- Command: Execute an action by name [ TBD after Dreamforce ]
Don’t miss this FREE training from Google Senior Engineer Mitch Spano. All sessions will be live stream on Apex Hours YouTube Channel at the scheduled time. Please follow our ApexHours website and subscribe to our YouTube Channel and click on the bell icon to get more notifications.
If you have any doubts or queries on any session then please add a comment in the respective session, our team will try to help you as soon as possible.
For more join, our telegram channels https://t.me/apexHours.
Apex Design Pattern Book
Don’t forget to buy the Apex Design Patterns book by Jitendra Zaa.
I hope this Apex Design patterns training will help you become a good developer. To learn more check the Apex Enterprise Patterns session from apex hours.