When should I use the constructor design pattern?

Hi I learn about design patterns and found a Builder design pattern. What are the benefits of this design pattern and when should I use it? I surf www.dofactory.com and www.blackwasp.com , but still don't understand the benefits. By the way, I'm new to template development, so please explain the simple ones to me.

Thanks in advance. Kevin

+6
source share
4 answers

The Builder design pattern helps us trim the creation of an object. It focuses on building a complex object step by step. It also provides the process of creating an object as a finished product. This means that the object must be massaged with some instructions before it is ready and can be used by others.

Typically, it allows you to encapsulate complex creation logic.

Figure Builder is very similar to a factory pattern. The key difference between a builder and a factory is that a builder is useful when you need to do a lot of things to create an object.

For more information:
http://en.wikipedia.org/wiki/Builder_pattern
http://www.codeproject.com/KB/architecture/Builder_Design_Pattern.aspx

+13
source

The Builder design pattern helps hide complex logic in the builder class. Suppose we are developing a solution that creates a large soccer field at different times of the year, chosen by users of the application. We will create a builder class and pass the season information object in the builder class. Then the builder class is responsible for building the field according to the seasons.

+3
source

Have you checked the Wikipedia Builder page ?

The goal is to abstract the steps of constructing objects so that various implementations of these steps can represent objects.

Wikipedia example in Java. This should help.

+2
source

The Builder sample design is used when we want an instance to perform specific tasks in a specific order, see the wiki template for details.

Hopes that help

+1
source

Source: https://habr.com/ru/post/886689/


All Articles