Implementing Decorator Design Pattern in Apex
This post is part of the series – Design Pattern in ApexI am sure as a developer, we all faced some situations where we need to have some kind of temporary fields just for calculation or displaying in the UI, but we don’t want to store that information in the database or more specific in object. To solve this type of problems, we have Decorator Design Pattern, which allows a user to add a new functionality to an existing object without modifying it’s internal structure. This pattern create a decorator class which wraps the original class and provides additional functionalities keeping class method signature same.Where I should use this design pattern?Below are few user cases, where we can use this design pattern -Say in a table, we are displaying a list of records and want to perform some operations on selected records. We can perform the same operation on each record, but from user interaction point of view, if we can provide some check-boxes so that user can select multiple records inside the table and perform the same operation on all the selected records. We can display check-box against each row, but that check-box information we will not store into the object level, these are only for Visual Force pages.Say when we are creating new accountss we are passing the same account information to some MDM (Master Data Management) system via integration. Once the...
Read More