Performance

Data Transfer Object
Intent Pass data with multiple attributes in one shot from client to server, to avoid multiple calls to remote server. Explanation Real world example We need to fetch information about customers from remote database. Instead of querying the attributes one at a time, we use DTOs to transfer all the relevant attributes in a single shot. In plain words Using DTO relevant information can be fetched with a single backend query.
Double Checked Locking
Intent Reduce the overhead of acquiring a lock by first testing the locking criterion (the “lock hint”) without actually acquiring the lock. Only if the locking criterion check indicates that locking is required does the actual locking logic proceed. Class diagram Applicability Use the Double Checked Locking pattern when there is a concurrent access in object creation, e.g. singleton, where you want to create single instance of the same class and checking if it’s null or not maybe not be enough when there are two or more threads that checks if instance is null or not.
Lazy Loading
Intent Lazy loading is a design pattern commonly used to defer initialization of an object until the point at which it is needed. It can contribute to efficiency in the program’s operation if properly and appropriately used. Class diagram Applicability Use the Lazy Loading idiom when eager loading is expensive or the object to be loaded might not be needed at all Real world examples JPA annotations @OneToOne, @OneToMany, @ManyToOne, @ManyToMany and fetch = FetchType.
Object Pool
Also known as Resource Pool Intent When objects are expensive to create and they are needed only for short periods of time it is advantageous to utilize the Object Pool pattern. The Object Pool provides a cache for instantiated objects tracking which ones are in use and which are available. Explanation Real world example In our war game we need to use oliphaunts, massive and mythic beasts, but the problem is that they are extremely expensive to create.
Service Locator
Intent Encapsulate the processes involved in obtaining a service with a strong abstraction layer. Class diagram Applicability The service locator pattern is applicable whenever we want to locate/fetch various services using JNDI which, typically, is a redundant and expensive lookup. The service Locator pattern addresses this expensive lookup by making use of caching techniques ie. for the very first time a particular service is requested, the service Locator looks up in JNDI, fetched the relevant service and then finally caches this service object.
Unit Of Work
Intent When a business transaction is completed, all the updates are sent as one big unit of work to be persisted in one go to minimize database round-trips. Explanation Real-world example Arms dealer has a database containing weapon information. Merchants all over the town are constantly updating this information and it causes a high load on the database server. To make the load more manageable we apply to Unit of Work pattern to send many small updates in batches.
Half-Sync/Half-Async
Intent The Half-Sync/Half-Async pattern decouples synchronous I/O from asynchronous I/O in a system to simplify concurrent programming effort without degrading execution efficiency. Class diagram Applicability Use Half-Sync/Half-Async pattern when a system possesses following characteristics: the system must perform tasks in response to external events that occur asynchronously, like hardware interrupts in OS it is inefficient to dedicate separate thread of control to perform synchronous I/O for each external source of event the higher level tasks in the system can be simplified significantly if I/O is performed synchronously.
Leader/Followers
Intent The Leader/Followers pattern provides a concurrency model where multiple threads can efficiently de-multiplex events and dispatch event handlers that process I/O handles shared by the threads. Class diagram Applicability Use Leader-Followers pattern when multiple threads take turns sharing a set of event sources in order to detect, de-multiplex, dispatch and process service requests that occur on the event sources. Real world examples ACE Thread Pool Reactor framework JAWS Real-time CORBA Credits Douglas C.
Master-Worker
Also known as Master-slave or Map-reduce Intent Used for centralised parallel processing. Class diagram Applicability This pattern can be used when data can be divided into multiple parts, all of which need to go through the same computation to give a result, which need to be aggregated to get the final result. Explanation In this pattern, parallel processing is performed using a system consisting of a master and some number of workers, where a master divides the work among the workers, gets the result back from them and assimilates all the results to give final result.