Design-Patterns

This repository is a summary of all design patterns which I've studied so far.


Project maintained by radubauzh Hosted on GitHub Pages — Theme by mattgraham

Overview

Design Patterns which I cover on this page

  1. Inheritance
  2. Singleton Design Pattern
  3. Adapter Design Pattern
  4. Composite Design Pattern
  5. Observer Design Pattern
  6. Command Design Pattern
  7. State Design Pattern
  8. Decorator Design Pattern
  9. Strategy Design Pattern
  10. Iterator Design Pattern
  11. MVC Design Pattern

What is a Design Pattern?

A Design Pattern is a pattern that captures a solution to a recurring design problem

Why design patterns?

Smart

Inheritance

Advantages Minimize the amount of duplicate code in an application by sharing common code amongst several subclasses Where equivalent code exists in two related classes, the hierarchy can usually be refactored to move the common code up to a mutual superclass. This also tends to result in a better organization of code and smaller, simpler compilation units.

Disadvantages

Singleton Design Pattern

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

singleton

Advantages

Disadvantages

Singleton vs. static method

public static Singleton getInstance() {
  if (uniqueInstance == null) {
    synchronized (Singleton.class) {
      if (uniqueInstance == null) {
        uniqueInstance = new Singleton();

Adapter Design Pattern

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

Image

Advantages

Disadvantages

Observer Design Pattern

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

The observer pattern provides an object design where subjects and observers are loosely coupled. Why?

Image

Advantages

Disadvantages

Examples Newspapers, Digital Clock, MVC Pattern, Datatable

Command Design Pattern

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

Image

Advantages

Disadvantages

## Iterator Design Pattern The Iterator Pattern provides a way to access the internal objects of an aggregate object sequentially without exposing anything about the internal structure of the encapsulation object. It provides access to a collection of objects encapsulated within another object without violating it’s encapsulation property

Image

Advantages

Disadvantages

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

Image

Advantages

Composite Design Pattern

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. (leaves)

Image

Advantages

Disadvantages

Strategy Design Pattern

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.

Image

Advantages

Disadvantages

Decorator Design Pattern

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

Image

Advantages

Disadvantages

Compound Pattern - MVC

It is a common architectural pattern which is used to design and create interfaces and the structure of an application. This pattern divides the application into three parts that are dependent and connected to each other. These designs are used to distinguish the presentation of data from the way the data is accepted from the user to the data that is being shown.

Image

Advantages

Disclaimer

I do not own those pictures. This repository is only for studying purposes. If you’re the owner of them, just contact me.