Design Patterns

--Originally published at Computer Systems Engineering

Design patterns are the common solutions to the common problems in software design. You could say that they are a series of rules you can follow if you stump into some inconvenient during your software design process. However, these just provide general solutions to problems so we actually need to learn how to apply them.

There is a long list of design patterns, each under its due clasification. These are:

Creational Patterns

These reffer to the instantiation of classes and how you do this to avoid duplication of code.

  • Abstract factory: creates an instance of several families of classes. It provides an interface for creating families of related objects without specifying their concrete class.
  • Builder: separates object construction from its representation. This can be used in a way that the same construction processes can create different representations.
  • Factory Method: creates an instance of several derived classes. It is basically an interface that the subclasses adapt to do their own specific tasks.
  • Prototype: a fully initialized instance that can be copied or cloned. It is used when direct creation of an object is costly, creates new objects by copying this prototypical instance.
  • Singleton: a class of which only a single instance can exist.

Structural Patterns

These patterns focus on the composition of classes and objects. With the use of inheritance and interfaces they allow objects to be build in a way that provides new funtionality.

  • Adapter: converts the interface of a class into another interface. This allows a class to work with another one even if it had an incompatible interface.
  • Bridge: separates an object’s interface from its implementation.
  • Composite: composes object intro tree structures to represent hierarchies.
  • Decorator: adds additional responsibilities to an object.
  • Facade: class that represents an entire subsystem.
  • Flyweight: it uses the shared characteristics
    Resultado de imagen para brain loading gif
    a large number of objects, ignoring the other characteristics of the objects that don’t have importance to the developer.
  • Proxy: placeholder for another object, this can be used to control the references to it.

Behavioral Patterns

Behavioral patterns focus on the communication that exist between objects.

  • Chain of responsibility: a way of passing a request between a chain of objects
  • Command: encapsulate a command request as an object
  • Interpreter: a way to include language elements in a program
  • Iterator: Sequentially access the elements of a collection
  • Mediator: Defines simplified communication between classes
  • Memento: Capture and restore an object’s internal state
  • Null Object: Designed to act as a default value of an object
  • Observer: A way of notifying change to a number of classes
  • State: Alter an object’s behavior when its state changes
  • Strategy: Encapsulates an algorithm inside a class
  • Template method: Defer the exact steps of an algorithm to a subclass
  • Visitor: Defines a new operation to a class without change

 

Resultado de imagen para brain loading gif(A lot of information at once I know)

References:

https://sourcemaking.com/design_patterns

https://airbrake.io/blog/design-patterns/software-design-patterns-guide