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.
Double Dispatch
Intent Double Dispatch pattern is a way to create maintainable dynamic behavior based on receiver and parameter types. Class diagram Applicability Use the Double Dispatch pattern when the dynamic behavior is not defined only based on receiving object’s type but also on the receiving method’s parameter type. Real world examples ObjectOutputStream
Event Driven Architecture
Intent Send and notify state changes of your objects to other applications using an Event-driven Architecture. Class diagram Applicability Use an Event-driven architecture when you want to create a loosely coupled system you want to build a more responsive system you want a system that is easier to extend Real world examples Chargify, a billing API, exposes payment activity through various events (https://docs.chargify.com/api-events) Amazon’s AWS Lambda, lets you execute code in response to events such as changes to Amazon S3 buckets, updates to an Amazon DynamoDB table, or custom events generated by your applications or devices.
Event Sourcing
Intent Instead of storing just the current state of the data in a domain, use an append-only store to record the full series of actions taken on that data. The store acts as the system of record and can be used to materialize the domain objects. This can simplify tasks in complex domains, by avoiding the need to synchronize the data model and the business domain, while improving performance, scalability, and responsiveness.
Execute Around
Intent Execute Around idiom frees the user from certain actions that should always be executed before and after the business method. A good example of this is resource allocation and deallocation leaving the user to specify only what to do with the resource. Explanation Real-world example A class needs to be provided for writing text strings to files. To make it easy for the user, the service class opens and closes the file automatically.
Factory
Also known as Simple Factory Static Factory Method Intent Providing a static method encapsulated in a class called the factory, to hide the implementation logic and make client code focus on usage rather than initializing new objects. Explanation Real-world example Imagine an alchemist who is about to manufacture coins. The alchemist must be able to create both gold and copper coins and switching between them must be possible without modifying the existing source code.
Factory Kit
Also Known As Abstract-Factory Intent Define a factory of immutable content with separated builder and factory interfaces. Explanation Real-world example Imagine a magical weapon factory that can create any type of weapon wished for. When the factory is unboxed, the master recites the weapon types needed to prepare it. After that, any of those weapon types can be summoned in an instant. In plain words Factory kit is a configurable object builder, a factory to create factories.
Factory Method
Also known as Virtual Constructor Intent Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. Explanation Real-world example Blacksmith manufactures weapons. Elves require Elvish weapons and orcs require Orcish weapons. Depending on the customer at hand the right type of blacksmith is summoned. In plain words It provides a way to delegate the instantiation logic to child classes.
Fan-Out/Fan-In
Intent The pattern is used when a source system needs to run one or more long-running processes that will fetch some data. The source will not block itself waiting for the reply. The pattern will run the same function in multiple services or machines to fetch the data. This is equivalent to invoking the function multiple times on different chunks of data. Explanation The FanOut/FanIn service will take in a list of requests and a consumer.
Filterer
Name / classification Filterer Intent The intent of this design pattern is to introduce a functional interface that will add a functionality for container-like objects to easily return filtered versions of themselves. Explanation Real world example We are designing a threat (malware) detection software which can analyze target systems for threats that are present in it. In the design we have to take into consideration that new Threat types can be added later.
Fluent Interface
Intent A fluent interface provides an easy-readable, flowing interface, that often mimics a domain specific language. Using this pattern results in code that can be read nearly as human language. Explanation The Fluent Interface pattern is useful when you want to provide an easy readable, flowing API. Those interfaces tend to mimic domain specific languages, so they can nearly be read as human languages. A fluent interface can be implemented using any of
Hexagonal Architecture
Also known as Ports and Adapters Clean Architecture Onion Architecture Intent Allow an application to equally be driven by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time devices and databases. Class diagram Applicability Use Hexagonal Architecture pattern when When the application needs to be independent of any frameworks When it is important that the application highly maintainable and fully testable Tutorials Build Maintainable Systems With Hexagonal Architecture Real world examples Apache Isis builds generic UI and REST API directly from the underlying domain objects Credits Alistair Cockburn - Hexagonal Architecture