- Dani: “Ahora hablaremos de Builder, ¿Qué te recuerda? ¿Cómo qué ideas te da?”
- Yo:
Introduccion
Dónde estamos y hacia dónde vamos
Patrones creacionales
Singleton
Singleton 101
Implementación de Singleton en JS
Contrastemos: Singleton con TS
Singleton: pros y contras
Factory
Factory 101
Diagrama de implementación de Factory
Implementación de Factory en JS
Contrastemos: Factory en TS
Factory: pros y contras
Abstract Factory
Abstract Factory 101
Diagrama de implementación de Abstract Factory
Implementación de Abstract Factory en JS
Contrastemos: Abstract Factory en TS
Abstract Factory: pros y contras
Builder
Builder 101
Diagrama de implementación de Builder
Implementación de Builder en JS
Contrastemos: Builder en TS
Builder: pros y contras
Prototype
Prototype 101
Diagrama de implementación de Prototype
Implementación de Prototype en JS
Contrastemos: Prototype en TS
Prototype: pros y contras
Conclusiones
¿Qué sigue sobre patrones de diseño?
You don't have access to this class
Keep learning! Join and start boosting your career
In the exciting world of software development, design patterns are essential to unify and standardize procedures. One of them is the Builder design pattern, which allows us to divide the creation of an object into particular steps. By following a uniform process, we can create different representations of the same object. For example, when building a vehicle, we use a series of steps that could be applied to both the construction of the vehicle itself and the structure of the user manual. It is this parallelism and the ability to vary representations that makes the Builder pattern remarkably useful.
In automobile manufacturing, new needs arise, as in the example of the sedan car. In this case, different versions are considered, such as CVT and Signature, where the color and number of airbags can be modified. Here the Builder pattern is ideal, since it allows managing these variants without creating an unnecessary number of product classes or factory classes that would complicate the code structure.
Definition of a base class or interface: This defines the general steps of product creation. In a vehicle production line, these steps may include the addition of tires, seats, among other elements.
Implementation of specific classes of Builders: Each of these classes is responsible for providing specific versions of the creation steps. For example, we can have a "SedanBuilder" and a "HatchbackBuilder", adjusting each step according to the type of vehicle.
Creation of concrete products: Here, the final objects that are returned do not need to follow a base class or interface; they can be specific, such as a Mastodon or a Rhino, allowing flexibility in the design.
A director class: This class manages the order of the construction steps. It knows the sequences for various versions of the same vehicle, such as a Signature of Sedan or Hatchback, and allows individual Builders to implement those steps in a custom manner.
The Builder is the solution to problems that other patterns, such as Factory or Abstract Factory, can solve, but in less optimal ways when it comes to creating multiple representations of the same product.
Factory: The suggestion of creating new factory classes for each new product can quickly escalate in complexity, especially when dealing with custom variants and schemas.
Abstract Factory: Although it improves on the previous approach by allowing to manage the return of different versions, it remains laborious due to the number of factory methods it would require.
Microscopic Builder: Passing many parameters to a builder can result in confusing and error-prone structures, especially when not all parameters are needed for each instance.
The Builder pattern, in contrast, offers a structured and flexible solution. By breaking down complex processes into simple, modular steps, it promotes cleaner, more manageable code.
Thus, the Builder stands as a powerful pattern, ideal for complex projects where customization and multiple representations are required without losing sight of efficiency. With it you can take your development to the next level and confidently face any challenge involving the creation of complex objects in software. Keep learning and exploring the fascinating world of design patterns!
Contributions 3
Questions 0
La clase directora establece la serie de pasos que se utilizan para construir un objeto; En cambio, la clase Builder proporciona la implementación de dichos pasos
Want to see more contributions, questions and answers from the community?