[GOF] Gang of Four Design Patterns


The four authors of the “Design Patterns: Elements of Reusable Object-Oriented Software” book Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides has first published this book.
Four authors were written this book that's why the name was given "Gang of Four".

Even though the GoF authors wrote the book in a C++ context, the book remains very relevant to Java programming. C++ and Java are both object-oriented languages.

Let me first define what is design pattern and it's usage in simple words.

What is Design Patterns?

In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.

Uses of Design Patterns

  • Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns.
  • Often, people only understand how to apply certain software design techniques to certain problems. These techniques are difficult to apply to a broader range of problems. Design patterns provide general solutions, documented in a format that doesn't require specifics tied to a particular problem.
  • In addition, patterns allow developers to communicate using well-known, well-understood names for software interactions. Common design patterns can be improved over time, making them more robust than ad-hoc designs.

Organizing the Catalog to Creational, Structural, or Behavioral

Design patterns are organized into Creational, Structural, or Behavioral purpose.
  1. Creational patterns concern the process of object creation. 
  2. Structural patterns deal with the composition of classes or objects. 
  3. Behavioral patterns characterize the ways in which classes or objects interact and distribute responsibility. 


Creational design patterns

Creational patterns involve object instantiation and all provide a way to decouple a client from the objects it needs to instantiate.

This pattern can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done. Click to read creational design patterns.

Structural design patterns

Structural pattern let's compose classes and objects into larger structures. Click to read structural design patterns.
  • Adapter Design Pattern - 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.
  • Bridge Design Pattern - Decouple an abstraction from its implementation so that the two can vary independently.
  • Composite Design Pattern - Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly
  • Decorator Design Pattern - Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
  • Facade Design Pattern - 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.
  • Flyweight Design Pattern - Use sharing to support large numbers of fine-grained objects efficiently.
  • Proxy Design Pattern - Provide a surrogate or placeholder for another object to control access to it.

Behavioral design patterns

Behavioral pattern is concerned with how classes and objects interact and distribute responsibility.
These design patterns are all about Class's objects communication. Behavioral patterns are those patterns that are most specifically concerned with communication between objects. Click to read behavioral design patterns.
  • Chain of responsibility - 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 with the chain until an object handles it.
  • Command Design Pattern - Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
  • Iterator Design Pattern - Accesses the elements of an object sequentially without exposing its underlying representation.
  • Mediator Design Pattern - Allows loose coupling between classes by being the only class that has detailed knowledge of their methods.
  • Memento Design Pattern - Provides the ability to restore an object to its previous state.
  • Observer Design Pattern - s a publish/subscribe pattern which allows a number of observer objects to see an event.
  • State Design Pattern - Allow an object to alter its behaviour when its internal state changes. The object will appear to change its class.
  • Strategy Design Pattern - Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from the clients that use it.
  • Template Method Design Pattern - 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.
  • Delegation Pattern - It is a technique where an object expresses certain behavior to the outside but in reality delegates responsibility for implementing that behaviour to an associated object.

References

The source code of all the Design Patterns on my Github repository :
https://github.com/RameshMF/gof-java-design-patterns

Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours


Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course

Comments