Developers around the world over the period of time invented some patterns (repeatable solutions) to solve some common occurring problems, we call it design patterns. We are working on multi tenant architecture in salesforce, all design patterns don’t work here. We have some tricky patterns here in Apex because of this architecture, we call it as Apex Design Patterns.

There are following 6 common design patterns in apex-
- Singleton – Its a design pattern which restricts the instantiation of a class to one “single” instance only within a single transaction context.
- Strategy – Its a behavioral design pattern that lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable. The Strategy pattern (aka the policy pattern) attempts to solve the issue where you need to provide multiple solutions for the same problem so that one can be selected at runtime.
- Decorator – This pattern allows you to add new functionality to an existing object without altering its structure. This type of design pattern comes under structural pattern as this pattern acts as a wrapper to existing class. This pattern creates a decorator class which wraps the original class and provides additional functionality keeping class methods signature intact.
- Facade – hides the complexity of the system and provides simple interface.
- Composite – lets you compose objects into tree structures and then work with these structures as if they were individual objects.
- Bulk State Transition – used to perform bulk actions efficiently based on change of state of one or more records.
To know more about these patterns, click on respective design pattern name.
Please note: There are no hard and fast rule to use these design patterns, you can use any other OO design patterns as well but make sure you are handling everything efficiently by taking care of governor limits.