Skip to content

Instantly share code, notes, and snippets.

@Eihen
Created March 9, 2022 18:57
Show Gist options
  • Save Eihen/b41a78d32675a3fd00af54ea3474308d to your computer and use it in GitHub Desktop.
Save Eihen/b41a78d32675a3fd00af54ea3474308d to your computer and use it in GitHub Desktop.

Backend Review

OOP

Encapsulation

Each object has its own private state, and it is not possible to access the state of another object, being only able to invoke a list of public functions. The object manage it's own state and no other class can alter it directly.

Abstraction

Expose only the relevant data of an object, and hide the details of its implementation. The actor interacting with an object does not need to know, nor does it care, about all the details of the object, only what is relevant for it's purpose.

Inheritance

One object is able to inherit properties of another object, and the child object can override the properties of the parent object to introduce new behavior.

Polymorphism

Multiple objects can share the same parent, and should be able to perform the same actions, but the behavior of each action may differ from the each other.

Single-responsability principle

A class should only have one job, giving it only one reason to change and only one place to change it.

Open-closed principle

A class should promote extensions of it's functionality, not modifications of the functionality. A class should be extended for more funcionality, while keeping the existing functionality untouched.

Liskov substitution principle

A subclass of a class should be able to handle any task the parent class can handle, in a way that it does not matter to the user if he is using the parent class or the subclass.

Interface Segregation principle

A class shoud not be able to perform tasks that are not needed for it's job. Those actions should moved to separate interfaces, which will be implemented only for classes who need them.

Dependency inversion principle

High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions represent the action to be performed, and should not be dependent on details of the implementation. The low-level module will be responsible for the details of the implementation, respecting the contract of the abstraction. The high-level module will depend on the abstraction, not needing to know the implementation details nor which low-level module will be used.

Transient

A new object is created every time one object is requested.

Scoped

A new object is created for every scope (request), reused for that scope, and destroyed when the scope ends.

Singleton

A new object is created for the application lifetime, reused for every scope, and destroyed only when the application ends.

Creational

  • Factory Method - Interface for creating an object, but let subclasses decide which class to instantiate.

  • Abstract Factory - Creates families of related objects, without specifying the concrete class.

  • Builder - Construct complex objects step by step, separating the construction from the representation, allowing the same construction process to create different representations.

  • Prototype - Clone existing objects without depending on their classes, delegating the responsability of creating the clone to the object begin cloned, those clonable objects are called prototypes.

  • Singleton - A class that has only one instance, and provides a global point of access to it.

Structural

  • Adapter - A class that mediates the communication between objects with incompatible interfaces.

  • Bridge - Lets you split a large class or a set of closely related classes into smaller classes in separate hierarchies, which can be developed independently. Promoting the change of the code from inheritance to composition.

  • Composite - Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

  • Decorator Lets you attach new behaviors to objects, without the need to modify the object itself, by adding new behavior objects to special wrappers in the original object. Promoting the change of the code from inheritance to composigion.

  • Facade

  • Flyweight

  • Proxy

Behavioral

  • Chain of Responsibility - Pass a request along a chain of handlers, each handler decide if they can handle the request of should pass it along the chain for the next handlers.

  • Command - Encapsulate a request as an standalone object, allowing the request to be passed as an argument, allowing queue or delay of the request, and support undoable operations on top of it.

  • Iterator - Provides a way of traversing the element of a collection without exposing its underlying representation.

  • Mediator - Restrict direct communication between objects, all communication will be handled by the mediator object, which is responsible for coordinating all objects.

  • Memento

  • Observer - Lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they're observing.

  • State - Encapsulate the state of an object, allowing the object to change its behavior when its state changes.

  • Strategy

  • Template Method

  • Visitor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment