| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system.
Design patterns can speed up the development process by providing tested, proven development paradigms.
Reusing design patterns helps to prevent subtle issues that can cause major problems, and it also improves code readability for coders and architects who are familiar with the patterns.
Creational design patterns abstract the instantiation process. They help make a system independent of how its objects are created, composed, and represented.
Structural patterns are concerned with how classes and objects are composed to form larger structures.
Behavioral patterns are concerned with algorithms and the assignment of responsibilites between objects.
Concurrency patterns are those types of design patterns that deal with the multi-threaded programming paradigm.
Presentation Tier patterns are the top-most level of the application, this is concerned with translating tasks and results to something the user can understand.
An architectural pattern is a general, reusable solution to a commonly occurring problem in software architecture within a given context.
Integration patterns are concerned with how software applications communicate and exchange data.
A programming idiom is a means of expressing a recurring construct in one or more programming languages. Generally speaking, a programming idiom is an expression of a simple task, algorithm, or data structure that is not a built-in feature in the programming language being used, or, conversely, the use of an unusual or notable feature that is built into a programming language. What distinguishes idioms from patterns is generally the size, the idioms tend to be something small while the patterns are larger.
Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Applicability: Use the Abstract Factory pattern when
Real world examples:
Intent: Separate the construction of a complex object from its representation so that the same construction process can create different representations.
Applicability: Use the Builder pattern when
Real world examples:
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.
Applicability: Use the Factory Method pattern when
Real world examples:
Intent: Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
Applicability: Use the Prototype pattern when a system should be independent of how its products are created, composed and represented; and
Real world examples:
Intent: Ensure a class only has one instance, and provide a global point of access to it.
Applicability: Use the Singleton pattern when
Typical Use Case:
Real world examples:
Intent: Convert the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
Applicability: Use the Adapter pattern when
Real world examples:
Intent: Decouple an abstraction from its implementation so that the two can vary independently.
Applicability: Use the Bridge pattern when
Intent: Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
Applicability: Use the Composite pattern when
Real world examples:
Intent: Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
Applicability: Use Decorator
Intent: Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
Applicability: Use the Facade pattern when
Intent: Use sharing to support large numbers of fine-grained objects efficiently.
Applicability: The Flyweight pattern's effectiveness depends heavily on how and where it's used. Apply the Flyweight pattern when all of the following are true
Real world examples:
Intent: Provide a surrogate or placeholder for another object to control access to it.
Applicability: Proxy is applicable whenever there is a need for a more versatile or sophisticated reference to an object than a simple pointer. Here are several common situations in which the Proxy pattern is applicable
Typical Use Case:
Real world examples:
Intent: Encapsulate the processes involved in obtaining a service with a strong abstraction layer.
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 relavant service and then finally caches this service object. Now, further lookups of the same service via Service Locator is done in its cache which improves the performance of application to great extent.
Typical Use Case:
Intent: Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
Applicability: Use Chain of Responsibility when
Real world examples:
Intent: Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
Applicability: Use the Command pattern when you want to
Typical Use Case:
Real world examples:
Intent: Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
Applicability: Use the Interpreter pattern when there is a language to interpret, and you can represent statements in the language as abstract syntax trees. The Interpreter pattern works best when
Intent: Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
Applicability: Use the Iterator pattern
Real world examples:
Intent: Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
Applicability: Use the Mediator pattern when
Intent: Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later.
Applicability: Use the Memento pattern when
Real world examples:
Intent: Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Applicability: Use the Observer pattern in any of the following situations
Typical Use Case:
Real world examples:
Intent: Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Applicability: Use the State pattern in either of the following cases
Intent: Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Applicability: Use the Strategy pattern when
Intent: Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
Applicability: The Template Method pattern should be used
Intent: Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.
Applicability: Use the Visitor pattern when
Real world examples:
Intent: Apply a "Separation of Concerns" principle in a way that allows developers to build and test user interfaces.
Applicability: Use the Model-View-Presenter in any of the following situations
Intent: Object provides an abstract interface to some type of database or other persistence mechanism.
Applicability: Use the Data Access Object in any of the following situations
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.
Applicability: Use the Double Checked Locking pattern when
Intent: Servant is used for providing some behavior to a group of classes. Instead of defining that behavior in each class - or when we cannot factor out this behavior in the common parent class - it is defined once in the Servant.
Applicability: Use the Servant pattern when
Intent: In most object-oriented languages, such as Java or C#, references may be null. These references need to be checked to ensure they are not null before invoking any methods, because methods typically cannot be invoked on null references. Instead of using a null reference to convey absence of an object (for instance, a non-existent customer), one uses an object which implements the expected interface, but whose method body is empty. The advantage of this approach over a working default implementation is that a Null Object is very predictable and has no side effects: it does nothing.
Applicability: Use the Null Object pattern when
Intent: A system with lots of objects can lead to complexities when a client wants to subscribe to events. The client has to find and register for each object individually, if each object has multiple events then each event requires a separate subscription. An Event Aggregator acts as a single source of events for many objects. It registers for all the events of the many objects allowing clients to register with just the aggregator.
Applicability: Use the Event Aggregator pattern when
Intent: Callback is a piece of executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at some convenient time.
Applicability: Use the Callback pattern when
Real world examples:
Intent: Provide pluggable filters to conduct necessary pre-processing and post-processing to requests from a client to a target
Applicability: Use the Intercepting Filter pattern when
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.
Applicability: Use the Execute Around idiom when
Intent: Create hierarchy of objects and new objects using already existing objects as parents.
Applicability: Use the Property pattern when
Real world examples:
Intent: Poison Pill is known predefined data item that allows to provide graceful shutdown for separate distributed consumption process.
Applicability: Use the Poison Pill idiom when
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.
Applicability: Use the Lazy Loading idiom when
Real world examples:
Intent: Service Layer is an abstraction over domain logic. Typically applications require multiple kinds of interfaces to the data they store and logic they implement: data loaders, user interfaces, integration gateways, and others. Despite their different purposes, these interfaces often need common interactions with the application to access and manipulate its data and invoke its business logic. The Service Layer fulfills this role.
Applicability: Use the Service Layer pattern when
Intent: Specification pattern separates the statement of how to match a candidate, from the candidate object that it is matched against. As well as its usefulness in selection, it is also valuable for validation and for building to order
Applicability: Use the Specification pattern when
Intent: Tolerant Reader is an integration pattern that helps creating robust communication systems. The idea is to be as tolerant as possible when reading data from another service. This way, when the communication schema changes, the readers must not break.
Applicability: Use the Tolerant Reader pattern when
Intent: Separate the user interface into three interconnected components: the model, the view and the controller. Let the model manage the data, the view display the data and the controller mediate updating the data and redrawing the display.
Applicability: Use the Model-View-Controller pattern when
Intent: Flux eschews MVC in favor of a unidirectional data flow. When a user interacts with a view, the view propagates an action through a central dispatcher, to the various stores that hold the application's data and business logic, which updates all of the views that are affected.
Applicability: Use the Flux pattern when
Intent: Double Dispatch pattern is a way to create maintainable dynamic behavior based on receiver and parameter types.
Applicability: Use the Double Dispatch pattern when
Real world examples:
Intent: Ensure a class only has limited number of instances, and provide a global point of access to them.
Applicability: Use the Multiton pattern when
Intent: Resource Acquisition Is Initialization pattern can be used to implement exception safe resource management.
Applicability: Use the Resource Acquisition Is Initialization pattern when
Intent: It is often the case that tasks to be executed are short-lived and the number of tasks is large. Creating a new thread for each task would make the system spend more time creating and destroying the threads than executing the actual tasks. Thread Pool solves this problem by reusing existing threads and eliminating the latency of creating new threads.
Applicability: Use the Thread Pool pattern when
Intent: Private Class Data design pattern seeks to reduce exposure of attributes by limiting their visibility. It reduces the number of class attributes by encapsulating them in single Data object.
Applicability: Use the Private Class Data pattern when
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.
Applicability: Use the Object Pool pattern when
Intent: Dependency Injection is a software design pattern in which one or more dependencies (or services) are injected, or passed by reference, into a dependent object (or client) and are made part of the client's state. The pattern separates the creation of a client's dependencies from its own behavior, which allows program designs to be loosely coupled and to follow the inversion of control and single responsibility principles.
Applicability: Use the Dependency Injection pattern when
Q: What is the difference between State and Strategy patterns?
While the implementation is similar they solve different problems. The State pattern deals with what state an object is in - it encapsulates state-dependent behavior. The Strategy pattern deals with how an object performs a certain task - it encapsulates an algorithm.
Q: What is the difference between Strategy and Template Method patterns?
In Template Method the algorithm is chosen at compile time via inheritance. With Strategy pattern the algorithm is chosen at runtime via composition.
Q: What is the difference between Proxy and Decorator patterns?
The difference is the intent of the patterns. While Proxy controls access to the object Decorator is used to add responsibilities to the object.
Q: What is the difference between Chain of Responsibility and Intercepting Filter patterns?
While the implementations look similar there are differences. The Chain of Responsibility forms a chain of request processors and the processors are then executed one by one until the correct processor is found. In Intercepting Filter the chain is constructed from filters and the whole chain is always executed.
To add a new pattern you need to do the following steps:
To work on one of the raised issues you need to do the following steps:
For creating/editing UML diagrams you need ObjectAid UML Explorer for Eclipse.
For inspiration check out the following sources:
Links to patterns applied in real world applications are welcome. The links should be added to the corresponding section of the README.md.
This project is licensed under the terms of the MIT license.
| Back | FazBrowse Home | New Git URL |