Visitor Pattern in Ruby
The visitor pattern in Ruby is a way of separating an algorithm from an object structure on which it operates.
A practical way to think about this is:
You have a bunch of objects (nodes) that need to be processed in some way
You don't want to add a new method to…
Template Method in Ruby
The template method in Ruby is one of the most practical design patterns in object-oriented programming.
The template method allows you to define the steps of an algorithm and then will enable subclasses to provide the implementation for one or more actions.
This is useful when you want to keep the overall algorithm the…
Flyweight Pattern in Ruby
The Flyweight pattern in Ruby is a software design pattern used to minimize memory usage by sharing as much data as possible. It is often used with other data structures, such as hash tables and trees.
The idea behind the flyweight pattern is to store data in a way that minimizes the amount…
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…