Comments on: C# Design Patterns – Faceted Builder https://code-maze.com/faceted-builder/ Learn. Code. Succeed. Wed, 09 Nov 2022 09:15:59 +0000 hourly 1 https://wordpress.org/?v=6.7.5 By: Marinko Spasojević https://code-maze.com/faceted-builder/#comment-6893 Wed, 09 Nov 2022 09:15:59 +0000 https://code-maze.com/?p=47241#comment-6893 In reply to karr.

In this specific case, it would work. But if you want to work with only a specific builder without a facade, then you will need that constructor.

]]>
By: karr https://code-maze.com/faceted-builder/#comment-6890 Wed, 09 Nov 2022 07:43:08 +0000 https://code-maze.com/?p=47241#comment-6890 Hi Marinko. We could remove the below constructors entirely and the code would still work. Am I right?

public CarInfoBuilder(Car car)
{
    Car = car;
}

public CarAddressBuilder(Car car)
{
    Car = car;
}

Thank you for the article.

]]>
By: Marinko https://code-maze.com/faceted-builder/#comment-1605 Mon, 18 Nov 2019 16:03:40 +0000 https://code-maze.com/?p=47241#comment-1605 In reply to A Muslim.

Hello A Muslim. Well, if you do something like this, you would have to have a car object inside the CarBuilderFacade constructor, but as you can see in the Program.cs class, we are using the constructor without parameters. Of course your solution would work if you add something like this:

var car = new CarBuilderFacade(new Car())

So, I would say it is all based on your preference, how you want to implement your solution. Anyhow, thank you a lot for your suggestion and for reading this article. Best regards.

]]>
By: A Muslim https://code-maze.com/faceted-builder/#comment-1604 Mon, 18 Nov 2019 15:38:06 +0000 https://code-maze.com/?p=47241#comment-1604 No Need to Initialize Car in the derived class. The Car property setter can be made private and can still be initialized in the base class by calling base class constructor.

public class CarAddressBuilder: CarBuilderFacade
{
public CarAddressBuilder(Car car):base(car)
{
//Car = car; //this is not really needed
}

]]>
By: James Curran https://code-maze.com/faceted-builder/#comment-613 Sat, 23 Feb 2019 09:48:23 +0000 https://code-maze.com/?p=47241#comment-613 There are two problem with this implementation:
There nothing to stop me from doing this, leaving me with a car with no type or color.
var builder = new CarBuilderFacade();
var coupe = builder
.Info.
.WithNumberOfDoors(2)
.Build();

Further, there’s also nothing to stop me from then doing this, leaving both sedan & coupe referring to the same 4-door car.

var sedan = builder
.Info.
.WithNumberOfDoors(4)
.Build();

]]>
By: Marinko https://code-maze.com/faceted-builder/#comment-695 Fri, 15 Feb 2019 18:58:28 +0000 https://code-maze.com/?p=47241#comment-695 In reply to James Curran.

Hello James. Well we could go even further and to expose just a wrapper around this creation to the client and to require all the data with a constructor (or any other variation). But, this is not the point here. We just show how can we combine two different builder classes to create a single complex object. Still, thank you for your comment and suggestion as well.

]]>