Apex Design Patterns

Book description

Harness the power of Apex design patterns to build robust and scalable code architectures on the Force.com platform

About This Book

  • Apply Creational, Structural and behavioural patterns in Apex to fix governor limit issues.
  • Have a grasp of the anti patterns to be taken care in Apex which could have adverse effect on the application.
  • The authors, Jitendra Zaa is a salesforce MVP and Anshul Verma has 12+ years of experience in the area of application development.

Who This Book Is For

If you are a competent developer with working knowledge of Apex, and now want to deep dive into the world of Apex design patterns to optimize the application performance, then this book is for you. Prior knowledge of Salesforce and Force.com platform is recommended.

What You Will Learn

  • Apply OOPs principal in Apex to design a robust and efficient solution to address various facets to a business problem
  • Get to grips with the benefits and applicability of using different design patterns in Apex
  • Solve problems while instantiating, structuring and giving dynamic behavior to Apex classes
  • Understand the implementation of creational, structural, behavioral, concurrency and anti-patterns in your application
  • Follow the Apex best practices to resolve governor limit issues
  • Get clued up about the Inheritance, abstract classes, polymorphism in Apex to deal with the object mechanism
  • Master various design patterns and determine the best out of them
  • Explore the anti patterns that could not be applied to Apex and their appropriate solutions

In Detail

Apex is an on-demand programming language providing a complete set of features for building business applications ? including data models and objects to manage data. Apex being a proprietor programming language from Salesforce to be worked with multi tenant environment is a lot different than traditional OOPs languages like Java and C#. It acts as a workflow engine for managing collaboration of the data between users, a user interface model to handle forms and other interactions, and a SOAP API for programmatic access and integration.

Apex Design Patterns gives you an insight to several problematic situations that can arise while developing on Force.com platform and the usage of Design patterns to solve them. Packed with real life examples, it gives you a walkthrough from learning design patterns that Apex can offer us, to implementing the appropriate ones in your own application. Furthermore, we learn about the creational patterns that deal with object creation mechanism and structural patterns that helps to identify the relationship between entities. Also, the behavioural and concurrency patterns are put forward explaining the communication between objects and multi-threaded programming paradigm respectively. We later on, deal with the issues regarding structuring of classes, instantiating or how to give a dynamic behaviour at a runtime, with the help of anti-patterns. We learn the basic OOPs principal in polymorphic and modular way to enhance its capability. Also, best practices of writing Apex code are explained to differentiate between the implementation of appropriate patterns. This book will also explain some unique patterns that could be applied to get around governor limits.

By the end of this book, you will be a maestro in developing your applications on Force.com for Salesforce

Style and approach

This book is a step-by-step guide, complete with well-tested programs and real world situations to solve your common occurring problems in Apex design by using the anti-patterns. It gets crackling from exploring every appropriate solution to comparing the best one as per OOps principal.

Table of contents

  1. Apex Design Patterns
    1. Apex Design Patterns
    2. Credits
    3. About the Authors
    4. About the Reviewer
    5. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book 
        3. Errata
        4. Piracy
        5. Questions
    7. 1. An Introduction to Apex Design Pattern
      1. Innovation
      2. Design patterns and learning
      3. Object-Oriented Programming (OOP)
      4. OOPs in play
        1. Static and dynamic dispatch
      5. An interface
      6. An abstract class
      7. Advantages of design patterns
      8. Design patterns and Apex
      9. Gang of Four (GoF)
      10. The SOLID principle
        1. The single responsibility principle (SRP)
        2. The open closed principle (OCP)
        3. The Liskov substitution principle (LSP)
        4. The interface segregation principle (ISP)
        5. The dependency inversion principle (DIP)
      11. Summary
    8. 2. Creational Patterns
      1. Factory method pattern
        1. Reflection in Apex
      2. Abstract factory pattern
        1. A new perspective on the abstract factory pattern
      3. The singleton pattern
      4. The builder pattern
        1. The difference between the abstract factory method and the builder pattern
      5. The prototype pattern
        1. The shallow and deep clone
      6. Summary
    9. 3. Structural Patterns
      1. The facade pattern
        1. Other use cases
        2. Points to consider
      2. The adapter pattern
        1. Points to consider
      3. The bridge pattern
        1. Points to consider
      4. The composite pattern
        1. Other use cases
        2. Points to consider
      5. The decorator pattern
        1. Other use cases
        2. Points to consider
      6. The flyweight pattern
        1. Other use cases
        2. Points to consider
      7. Summary
    10. 4. Behavioral Patterns
      1. The chain of responsibility pattern
        1. Points to consider
      2. The command pattern
        1. Some points to note
      3. The interpreter pattern
        1. Points to consider
      4. The iterator pattern
        1. Points to consider
      5. The visitor pattern
        1. Single dispatch
        2. Double-dispatch
          1. Guidelines to implementing the visitor pattern
        3. Points to consider
      6. The memento pattern
        1. Points to consider
      7. The observer pattern
        1. Point to consider
      8. The state pattern 
        1. Points to consider
      9. The strategy pattern
        1. Points to consider
      10. Summary
    11. 5. Handling Concurrency in Apex
      1. Understanding concurrency issues
      2. Reproducing concurrency problems in Apex
      3. The active object pattern
        1. Points to consider
      4. Summary
    12. 6. Anti-patterns and Best Practices
      1. Over usage of formula fields
        1. The deterministic formula field
        2. The nondeterministic formula field
      2. Functional decomposition
      3. Ignoring the equals() and hashcode() methods while performing object comparison
      4. Circular dependencies
        1. Circular dependency in Apex classes
        2. Circular dependency in triggers
        3. Other examples
      5. The ignoring toString() method
      6. Avoid the God class
      7. Error hiding
      8. Hard-coding
      9. Magic strings and numbers
      10. Inheritance hell
      11. SOQL inside a loop
      12. DML inside a loop
      13. Summary

Product information

  • Title: Apex Design Patterns
  • Author(s): Jitendra Zaa, Anshul Verma
  • Release date: April 2016
  • Publisher(s): Packt Publishing
  • ISBN: 9781782173656