July 2025 Apex Insider Newsletter
July comes in with fireworks and celebration — are you ready to start your month off with a bang by learning some new development concepts?
Demystifying Design Principles: Your Foundation for Better Code
You’ve got the basics of writing code down, so what about going to the next level in your coding?
Enter design principles: the fundamental guidelines that separate good code from great code. These aren’t rigid rules that constrain you, but philosophical guideposts that help you make better architectural decisions. Just like following the best practice of "one trigger per sObject" in Salesforce development, design principles give you a reliable framework for building robust software systems.
Meet the SOLID Principles
Among the most influential design principles for object-oriented languages (of which Apex is one) are the SOLID principles, introduced by software engineer Robert C. Martin in 2000. This memorable acronym represents five core principles that have transformed how developers approach object-oriented design:
- Single Responsibility Principle
- Open-Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
Over the next few issues, we'll dive deep into each principle, starting with the foundation: the Single Responsibility Principle.
The "S" in SOLID: Single Responsibility Principle
The Single Responsibility Principle, or SRP, states that "a module should have only one reason to change." In everyday language, this means that each class should have one job and do it well. This is closely related to another concept you’ve already learned through Cloud Code Academy, the “separation of concerns”.
Let's illustrate this with a Salesforce example that many of you already know. Imagine you're building a trigger framework. Following SRP, you'd create the trigger, plus these two classes:
- A TriggerHandler class for each object that orchestrates which methods to call for each trigger context
- A separate Helper class that contains the actual trigger-related business logic
Why split these responsibilities? When you need to add new business logic, you do the primary modification to the Helper class, while just adding a method invocation or two to the Handler class. When you need to adjust the trigger flow, you only modify the Handler class. Each class has a separate responsibility, and therefore a single, clear reason to change.
This principle extends to your methods too. Methods are more efficient, not to mention easier to read, understand, and debug when they too have only one job. So instead of writing one massive method to handle validation, data transformation, and database operations, give each of these tasks its own method. And, if necessary, use a larger method to call these individual methods.
Further Resources on SOLID and the SRP
- Article: SOLID Design Principles Explained—Building Better Software Architecture
- Video: SOLID Principles: Do You Really Understand Them?
- Article: The Single Responsibility Principle
- Video: SOLID Design Principles in Salesforce - The Single Responsibility Principle
Coming Up Next in Our SOLID Series
In a future issue, we'll continue exploring the SOLID principles with the Open-Closed Principle and discover how to write code that's open for extension but closed for modification. Stay tuned!
Cloud Coder Wins in June (and the very end of May) 2025
Cloud Coders continued to rack up accomplishments galore in the month of June. Here’s what some of us accomplished last month, with a few stragglers from the very end of May thrown in:
- Jarhud Augustin passed the Platform Developer I certification exam.
- Marek Oleksik won the second May Lightning Challenge code contest.
- Terrence Gonsalves won the voucher drawing for the second May Lightning Challenge code contest.
- Piotr Zogata completed the Developer Kickstart capstone project.
- weirdsourcer passed the Platform Developer I certification exam.
- Katende S. Kinene completed the Developer Kickstart capstone project.
- Temitayo Oluwalade passed the Platform Developer I certification exam.
- Neeyil won the first June Lightning Challenge code contest.
- Adrienne Millican started a new position as a Salesforce Developer.
Responses