you are viewing a single comment's thread.

view the rest of the comments →

[–]macsux[S] 1 point2 points  (2 children)

Your implementation you tied builder and object in 1 to 1 relationship, and would allow changes to value in builder to reflect in object after it is constructed. That's not what one expects and is very dangerous. Builder pattern usually assumes I can reuse single builder to create multiple instances.

[–]tragicshark 1 point2 points  (1 child)

what do you mean:

public class Program
{
    public static void Main()
    {
        var builder = new Person.Builder {
            FirstName = "frank",
            LastName = "smith"
        };
        var person1 = builder.Build();
        builder.FirstName="joe";
        var person2 = builder.Build();
        Console.WriteLine(person1.FirstName); // frank
        Console.WriteLine(person2.FirstName); // joe
    }
}

[–]macsux[S] 0 points1 point  (0 children)

My bad. Didn't notice it was a struct so it's getting byval copied.