Facade Pattern in Ruby
The facade pattern in Ruby and OOP is a standard way to simplify interfaces.
In Ruby, you provide a new API that should look simpler than the real API.
You can use this pattern to rewrite 3rd part API, as a wrapper API, or to build an API in front of your database.
For example:
class…
State Pattern in Ruby
The State Pattern in Ruby is a widely used design pattern that allows an object to change its behavior based on its internal state.
An everyday use case for the state pattern is a simple state machine.
For example, you could use the state pattern to implement a simple text editor with different modes…
Memento Pattern in Ruby
The memento pattern in Ruby is a design pattern that allows you to save an object's state and restore it later.
This can be useful for things like undo/redo or for storing the state of an object so that you can resume from that point if the program crashes.
This article will implement the…
The Prototype Pattern in Ruby
The prototype pattern in Ruby is a creational design pattern used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new things.
This pattern is used to:
Avoid subclasses of an object creator
Avoid the inherent cost of creating a new object…
Mediator Pattern in Ruby
The Mediator Pattern in Ruby allows communication between two or more classes by encapsulating how these classes interact.
This means that you should use a mediator class when you have a group of classes that need to interact, and you want to remove the dependency between those classes.
For example, if you have several…
Chain of Responsibility Pattern in Ruby
The chain of responsibility pattern is used to process varied requests, each of which may be handled by a different handler.
A handler is responsible for completing a request, but they can delegate that responsibility to other handlers, making it a chain of responsibility.
Benefits and drawbacks
There are many benefits to…
Bridge Pattern in Ruby
The bridge pattern in Ruby is a design pattern used in software engineering. The bridge pattern is useful for situations where you want to:
- Decouple an abstraction from its implementation so that they can vary independently.
- Create a new abstraction similar to an existing one but with different implementations.
- Keep an abstraction…
Abstract Factory in Ruby
The abstract factory in Ruby is an interface or class that provides a way to create families of related or dependent objects without specifying their concrete classes.
Abstract Factory is a creational, structural design pattern that provides one of the best ways to create an object. This pattern is useful when your code…
Policy Pattern in Ruby
The policy pattern in Ruby is a widely used software design pattern that allows you to encapsulate different behavior in separate classes, aka policies.
In general, you would use this pattern when you have a different behavior that needs to be applied in different circumstances.
For example, you may want to apply a discount…
Iterator Pattern in Ruby
If you want to discover how to implement the iterator pattern in Ruby, this tutorial is for you!
It's common to need to iterate over a collection of objects in Ruby. For example, you have an array of User objects, and you need to go over each one of them…