The first thing that we are going to discuss about is the builder factor, so the builder pattern is
a technique that is widely used by software engineers when trying to manage the creation of complex
objects.
But what exactly do we need to use the builder, Patrick?
Well, our situation would be when trying to create complex objects, that requires a lot of parameters,
especially when those parameters need to be supplied at any summarisation phase.
So in a constructor, for example, or when trying to prevent mistakes from creating a complex object
by supplying the parameters that we need to supply in a different order than the one that is expected.
And also when trying to avoid unreadable code that is caused by big constructors, when those big constructors
are needed in order to create some really, really complicated objects in our program, let's see a
typical issue that can be solved by using the builder pattern in the code.
So let's assume that we are working on an online store application, so the most complex object that
I can think of is the user account for our online store.
So like most of those stores, we are collecting some data regarding the user.
So we are assigning an ID for it.
We also collect the names you address, the budget and the discount rate that we may apply to to this
user.
And this is, of course, another simplified example, because applications tend to be more complex
than to have more complex objects inside them.
So now you can see this constructor here.
It's it doesn't look good at all.
It has a long list of parameters that we need to supply in it.
So this is considered to be a bad practice, right.
Because you can easily mistake the order of the parameters so you can easily put inside the budget.
You can put other parameters like we will see in in the example.
So you should avoid this type of these types of constructors right.
In your code.
But you can see it's pretty straightforward.
So we are assigning the ID, the name, the address budget in this country to each and every property
of this class.
So let's see in the upper class here where we have the main method, we created two objects, two users.
The first one is John Smith.
And here we are saying I need a name and address, a budget and also a discount rate.
So basically, this user, we have a discount of two percent to our products.
And for the second one, you can see that it's pretty much the same except for the data itself.
But here we have the budget of two and a discount rate of 100 percent.
So basically we reduced the budget of the user and also we applied a discount of 100 percent to everything
that this user will be buying.
So this this is actually an example of mistakingly putting the wrong parameters in the wrong border.
So we need to find a way to prevent this type of mistake.
And by the way, if you know such such an application, such an online store, just let me know, because
this this can be a very useful issue to exploit.
Right.
So joining me in the next video where we are going to talk about how exactly we can prevent such such
an error.