Skip to content

AncientMariner/Patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design Patterns code examples

---------------------------------------------------------------------

A Pattern is a solution to a problem in a context.

An Anti-Pattern tells you how to go from a problem to a BAD solution.

Behavioral:

The Chain of responsibility In object-oriented design, the chain-of-responsibility pattern is a behavioral design pattern consisting of a source of command objects and a series of processing objects.

The Command Pattern encapsulates a request as an object, thereby letting you parametrize other objects with different requests, queue or log requests, and support undoable operations.

The Execute around method Execute around pattern executes a given block of code with a pre and post operations, this pattern is very useful when dealing with expensive resources and can be used to close the resources instead of relying on the callers to close the resource.

The Interpreter Pattern is used to defines a grammatical representation for a language and provides an interpreter to deal with this grammar

The Iterator Pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

The Mediator Allows loose coupling by encapsulating the way disparate sets of objects interact and communicate with each other. Allows for the actions of each object set to vary independently of one another.

The Memento Memento design pattern is used when we want to save the state of an object so that we can restore later on.

The Monad In functional programming, a monad is a structure that combines program fragments (functions) and wraps their return values in a type with additional computation.

The NullObject All the objects are access via references, 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.

The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.

The State Pattern allows an object to alter its behavior when its internal state changes. The object will appear to change its class.

The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

The Template Pattern defines the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.

The Visitor Visitor pattern is used when we have to perform an operation on a group of similar kind of Objects. With the help of visitor pattern, we can move the operational logic from the objects to another class

Creational:

The Builder The intent of the Builder design pattern is to separate the construction of a complex object from its representation

The Compound pattern combines patterns with each other.

The Factory Method Pattern defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

The ObjectPool Object pooling can offer a significant performance boost; it is most effective in situations where the cost of initializing a class instance is high, the rate of instantiation of a class is high, and the number of instantiations in use at any one time is low

The Prototype Prototype design pattern is used when the Object creation is a costly affair and requires a lot of time and resources and you have a similar object already existing

The Singleton Pattern ensures a class has only one instance, and provides a global point of access to it.

Structural:

The Adapter Pattern converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

The Bridge Decouple an abstraction from its implementation so that the two can vary independently

The Composite Pattern allows you to compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

The Decorator Pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

The Facade Provide a unified interface to a set of interfaces in a subsystem. Facade Pattern defines a higher-level interface that makes the subsystem easier to use

The Flyweight Use sharing to support large numbers of fine-grained objects efficiently

The PrivateClass Private Class Data Pattern addresses the issue a class may have, concerning around protecting object state, where final cannot be declared

The Proxy Pattern provides a surrogate or placeholder for another object to control access to it.

About

Design Patterns

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages