Questions tagged [builder-pattern]

Separate the construction of a complex object from its representation so that the same construction process can create different representations. This tag is a synonym of the more frequently used [builder]; please use that tag instead of this one.

This pattern allows a client object to construct a complex object by specifying only its type and content, being shielded from the details related to the object's representation. This way the construction process can be used to create different representations. The logic of this process is isolated from the actual steps used in creating the complex object, so the process can be used again to create a different object from the same set of simple objects as the first one.

Credit to OODesign Principle

This tag is a synonym of the more frequently used ; please use that tag instead of this one.

238 questions
0
votes
1 answer

C++ template issue to Pull Up the Builder pattern into a configuration?

I have an algorithm that requires a large number of parameters (i.e. configuration) as part of its constructor and also requires some clearly defined creational steps. Therefore I have created a Builder Pattern implementation that allows to set the…
SkyWalker
  • 13,729
  • 18
  • 91
  • 187
0
votes
2 answers

Java Pattern to build object where any one field must be set?

I need to build objects of a class which has 3 fields: A, B and C. A valid object has at least one of A, B or C set by the user. I looked into the Builder Pattern, which is close to what I want, but only 1 field is made mandatory. I want that 1…
ask
  • 2,160
  • 7
  • 31
  • 42
0
votes
2 answers

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…
mezoid
  • 28,090
  • 37
  • 107
  • 148
0
votes
2 answers

One builder method implementation for all sub-classes (generics?)

My dilema is in creating one method that follows the builder pattern, which sets a variable and returns itself, but I have an interface Visitor which is implemented by BasicVisitor and that is extended by other visitor implementations. Furthermore,…
knownasilya
  • 5,998
  • 4
  • 36
  • 59
0
votes
2 answers

jQuery Method Chaining vs. C#/VB Lack of Method Chaining

What intrinsic properties of jQuery and the requirements it satisfies makes it such a good candidate for the builder pattern and method chaining? Asked another way, could the C#/VB .NET core libraries be rewritten with much more method chaining…
Chad
  • 3,159
  • 4
  • 33
  • 43
-1
votes
1 answer

Alternate implementation of Builder Pattern. Anything wrong with this?

Most of the implementations of Builder pattern I have seen are along these lines: https://github.com/Design-pattrns/Builder-Pattern/blob/master/src/Computer.java Basically the nested builder class needs to mirror all the attributes of the class that…
Marco Polo
  • 113
  • 1
  • 6
-1
votes
3 answers

Builder Pattern: Can't we simplify the creation of a builder object?

Just getting my head around the Builder pattern and I have a few (noob) questions. Mainly, why can't we just simplify the creation of a builder object? Instead of this: public final class Foo { private final String name; private final…
superigno
  • 994
  • 2
  • 12
  • 24
-1
votes
1 answer

Builder Pattern Java: How to reference generic type in BaseBuilder for Generic BaseClass

I want to implement Builder pattern for Generic Base class and Sub class stuck at defining Generic type in Base Builder. Here are the classes. Sub Class: public class Sub extends Base { private final String key; private Sub(Builder…
sp19
  • 3
  • 2
-1
votes
2 answers

How to create builder chain

I would like to create builder chain where I can provide different sets of methods based on the value of i. If I can use these intermediate builder classes then I can limit the available methods at compile-time rather than relying on runtime checks.…
-1
votes
1 answer

Which code is more readable?

This isn't a difficult question. I simply want to know which of these two C++ code snippets you think is better (readability vs. length vs. boiler-platery): Option #1 Entity* square = Entity::Builder().positionX(0.0).positionY(0.0). …
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
-1
votes
1 answer

C++ runtime error with shared_ptr and builder pattern

I was studying c++ language with shared pointer and builder pattern. I have written following code that is not working but I don't understand why it emits run-time error. Could you tell me why it is not working well and how can I solve this…
Likoed
  • 533
  • 2
  • 5
  • 15
-2
votes
1 answer

C++, Can I use default constructor in builder pattern? Please check my problem and my solution

class Email { public: //Email(){} //If I added this, this problem is resolved. But I am not sure this is good solution. Email(EmailBuilder builder){ ... } public class EmailBuilder { EmailBuilder() {...}; EmailBuilder…
sensolama
  • 23
  • 4
-3
votes
3 answers

is this the right way to make builder pattern in real software environment? in short what is the best way to create builder pattern in java

is this the right way to create builder pattern in java, if not what could be possible changes. tried with static class public class Multiverse { private UUID universeId; private String universeName; private String universeType; …
1 2 3
15
16