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
1
vote
1 answer

Default setter param in C#

I have a class I want to implement, but there is a lot of conditional logic so I decided to implement a builder(like) pattern. These setters will pretty much only be flags to set private class MockBuilder { private bool _flag1 = false; private…
1
vote
3 answers

Java reduce number of constructors

Suppose I have some class that has constructors, each of which has 2 params for example I have 5 types, two of them can be passed as first param and three as second Suppose the types are A,B,C,D,E. Basically I have something like this: public…
Mike Herasimov
  • 1,319
  • 3
  • 14
  • 31
1
vote
2 answers

Is there a design pattern for creating a prototype with only some values differing?

The client uses them via the base class (java code) : BaseClass baseObj1 = new DerivedClass("valueofreqdfeature"); //the required feature gets added to the map in the base class Map features =…
1
vote
1 answer

Can I make abstract fragment class with builder pattern?

I makes some fragments extends topFragment class. But it has variable arguments - custom listeners, some models, etc. public abstract class TopFragment extend Fragment { public interface OnCustomListener { void onCustomListener(); } …
myoungjin
  • 895
  • 1
  • 13
  • 27
1
vote
2 answers

Databuilder pattern issue

I am playing with data builder pattern, and I am failing to understand some behaviours. I wrote this simplified version of what I am trying to achieve below public abstract class DataBuilderParent { private MyParent myParent; …
adminSoftDK
  • 2,012
  • 1
  • 21
  • 41
1
vote
1 answer

Guice injection with Builder pattern for client lib

I am new to Google Guice and am trying to wrap my head around how to use it for my particular scenario. I am building a service client that is pretty complex and that (I believe) truly requires a Builder Pattern to be instantiated correctly. Because…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
1
vote
1 answer

Builder vs Factory Method pattern

I was reading about Builder pattern and as usual I got confused with Factory pattern. I have seen a good article which shows the difference between Abstract Factory and Builder…
Dev
  • 309
  • 1
  • 8
  • 24
1
vote
4 answers

How to use Builder pattern as described by Joshua Bloch's version in my ModelInput class?

I am trying to use Builder Pattern for my below class.. Initially I was using constructor of my class to set all the parameters but accidentally I came across Builder pattern and it is looking good for my use case. Below is my class in which people…
user2467545
1
vote
0 answers

Is this on a right creational pattern way?

I'm new to design patterns, and wondering what the particular kind of design pattern is (if there's any) inside the code snippet listed below. Basically there's a base class, which knows how to build a BaseProperty object: public abstract class…
1
vote
2 answers

Making database table choices static as possible without using Strings

First of all this question will be kind of long but in order to explain my problem in full i feel that i have to give you alot of information on my project so please bear with me! I am working for a company that uses charts alot so to avoid the…
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
1
vote
2 answers

Does the Builder pattern replace the 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.
Ashish Ashu
  • 14,169
  • 37
  • 86
  • 117
1
vote
1 answer

Do the Builder Pattern apply this requirement?

I have a web app, in the startup a servlet creates various instances of the same 'Product', Gateway, with different configuration settings defined. Here is a small description. Gateway: abstract class defines different types of…
vvra
  • 2,832
  • 5
  • 38
  • 82
0
votes
2 answers

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…
n8wrl
  • 19,439
  • 4
  • 63
  • 103
0
votes
1 answer

How to implement the Builder Design Pattern with the use of smart pointers?

I want to implement the builder pattern in C++ for a project that I am working on. I have found plenty of examples of this design pattern that uses raw pointers, but none that uses smart pointers. Since my opinion is that smart pointers are the way…
0
votes
2 answers

Inherit variables from abstract superclass

I'm trying to implement a BuilderPattern, where a subclass must extend a superclass. Superclass: @Getter public abstract class CommonValidatorConfig> { private boolean canBeNull; private boolean…
Paul Marcelin Bejan
  • 990
  • 2
  • 7
  • 14