builder-pattern

What is the difference between Builder Design pattern and Factory Design pattern?

What are the "Builder Design pattern" and "Factory Design pattern" the difference? Which is more advantageous? I want to test this patterns? How do I represent as a graph? ...

public class member visible to descendents

I have been getting a lot of traction from a builder pattern as a public class member of another class: public class Part { public class Builder { public string Name { get; set; } public int Type { get; set; } public Part Build() { return new Part(Name, Type); } } pro...

Is Builder pattern replace factory pattern?

I know this question is asked many times but I just want to clear more on this. Can a builder pattern replace factory pattern. Yes Builder pattern create and return a complex object step by step and this can be done in factory pattern also. ...

How do I create a builder in C# for an object that has properties that are referenc types?

I've started to construct a builder so that I can easily create test data for unit tests I am writing. The basic structure of the builder is: public class MyClassBuilder { public int id = 0; //setting the default value here //allows MyClass to be built with a specific id public MyClassBuilder WithId(int id) { t...

How to improve the builder pattern?

Motivation Recently I searched for a way to initialize a complex object without passing a lot of parameter to the constructor. I tried it with the builder pattern, but I don't like the fact, that I'm not able to check at compile time if I really set all needed values. Traditional builder pattern When I use the builder pattern to creat...

Builder vs Flyweight Pattern

What is the difference between Builder Pattern and Flyweight Pattern in terms of usage, as both of them deals with large number of objects? ...

Where would you use a Builder Pattern instead of an Abstract Factory?

I've seen this question rise here and there a few times, but I never found and answer I was happy with. From Wikipedia: Builder focuses on constructing a complex object step by step. Abstract Factory emphasizes a family of product objects (either simple or complex). Builder returns the product as a final step, but as far as the Abst...

Should a Test Data Builder construct defaults for it's non-primitives?

I've created a data builder in order to create test data in my unit tests. My data builders create defaults for all properties so that the tests that use them only need to specify the properties that are applicable to the test. Consider the following builder: public class CustomerBuilder { public int id = 0; public Order order ...

dynamic views stored in xml

So, We are currently looking at creating a web app in MVC with mind to creating a win forms app at a later date. The two will be almost identical in layout and usage. With this in mind we are looking at creating our MVC views by dynamically creating the html controls from an xml file. Such as <Page> <ID>Site</ID> <Object> <I...

Automatic generation of immutable class and matching builder class

What tools/libraries exist that will take a struct and automatically generate an immutable wrapper and also a "builder" class for incrementally building new instances? Example input: struct Foo { public int apples; public int oranges; public Foo Clone() {return (Foo) base.MemberwiseClone();} } Example output: public clas...

Builder pattern and persistent state : Test Data Builders

Does anyone have any links to some code they like that shows a good example of this in c#? As an example of bad code, here is what a builder I have now looks like. I'm trying to have a way to keep the flexibility of the builder pattern but not rebuild the properties. Cheers, Berryl public abstract class ActivityBuilder { public a...

Psuedo-Backwards Builder Pattern?

In a legacy codebase I have a very large class with far too many fields/responsibilities. Imagine this is a Pizza object. It has highly granular fields like: hasPepperoni hasSausage hasBellPeppers I know that when these three fields are true, we have a Supreme pizza. However, this class is not open for extension or change, so I can'...

Builder pattern vs. config object

The builder pattern is popular to create immutable objects, but there is some programming overhead to create a builder. So I wonder why not to use simply a config object. The usage of a builder would look like this: Product p = Product.name("Vodka").alcohol(0.38).size(0.7).price(17.99).build(); It is obvious that this is very readabl...

What would be considered good examples of implementing the builder pattern when used in the development of a GUI?

Hi Coders, I am a complete newbie when it comes to the use of factory classes and methods, patterns, etc - in fact I first learned of them here on Stackoverflow when browsing Java related questions :-) In response to a previous question of mine it was suggested that I look into the use of the Builder Pattern in the development of my GU...

Is this a valid Java implementation of an immutable class and the Builder pattern?

The Builder implements Cloneable and overrides clone() and instead of copying every field of the builder, the immutable class keeps a private clone of the builder. This makes it easy to return a new builder and create slightly modified copies of an immutable instance. This way I can go MyImmutable i1 = new MyImmutable.Builder().foo(1)....

Builder Pattern in Ruby with YAML

I have an instance of the Builder pattern in my project right now. Currently, the supported output format is CSV, however I would now like to include YAML. Easy, I thought. I have all of the supporting code in to make the type change. I'm finding myself to be in a bit of a complex. The intent of using the Builder pattern was to construc...