Skip to content

baonguyen96/DesignPatterns

Repository files navigation

GoF Design Patterns

Java CI with Maven

Introduction

This repository is collection of simple demos and examples for each and every GoF design patterns.

Additional resources (but not limited to) can be found at:

  1. Wikipedia
  2. Refactoring Guru
  3. Scaler Topics
  4. Source Making

Setup

  1. Java 1.8 or above
  2. Maven, preferably Maven 3
  3. Tests with JUnit4, Jacoco, Surefire

Patterns

Behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.

Source: Source Making

  • Chain of Responsibility: object that can fulfill a request
  • Command: when and how a request is fulfilled
  • Interpreter: grammar and interpretation of a language
  • Iterator: how an aggregate's elements are accessed and traversed
  • Mediator: how and which objects interact with each other
  • Memento: what and when private information is stored outside an object
  • Observer: number of objects that depend on another object, how the dependent objects stay up-to-date
  • State: states of an object
  • Strategy: implementation of different algorithms at runtime
  • Template Method: steps of an algorithm
  • Visitor: operations that can be applied to object(s) without changing their class(es)
Creational patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or in added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation.

Creational design patterns are composed of two dominant ideas. One is encapsulating knowledge about which concrete classes the system uses. Another is hiding how instances of these concrete classes are created and combined.

Creational design patterns are further categorized into object-creational patterns and class-creational patterns, where object-creational patterns deal with object creation and class-creational patterns deal with class-instantiation. In greater details, object-creational patterns defer part of its object creation to another object, while class-creational patterns defer its object creation to subclasses

Source: Wikipedia

  • Abstract Factory: interface for creating families of related/dependent objects without specifying their concrete implementations
  • Builder: how a composite object gets created
  • Factory Method: subclass of object that is instantiated
  • Prototype: class of object that is instantiated
  • Singleton: the sole instance of a class

Structural design pattern is a blueprint of how different objects and classes are combined to form a bigger structure for achieving multiple goals altogether. The patterns in structural designs show how unique pieces of a system can be combined in an extensible and flexible manner. So, with the help structural design pattern we can target and change a specific parts of the structure without changing the entire structure.

Source: Scaler Topics

  • Adapter: allows objects with incompatible interfaces to collaborate
  • Bridge: split a large class or a set of closely related classes into two separate hierarchies—abstraction and implementation—which can be developed independently of each other
  • Composite: composition of an object in a tree-like structure
  • Decorator: responsibilities of an object without subclassing
  • Facade: interface to a subsystem
  • Flyweight: optimize storage costs of similar objects
  • Proxy: provide a substitute or placeholder for another object

About

Gang of Four Design Patterns

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages