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

Java Builder Object Printing Null

I have created a Person, class and a Professor class that both use the Builder Pattern to create objects. The Professor class takes a Person object as an argument in its constructor. I am trying to use both classes together, but when I attempt to…
0
votes
1 answer

Builder pattern - child instance cannot work with methods of the parent abstract class

I am creating DTO structure with Builder pattern. Because of existence of many requests I created parent request AbstractRequest to create concrete requests - e.g. ConcreteRequest in this example. Base Buildable interface defines contract to all…
jnemecz
  • 3,171
  • 8
  • 41
  • 77
0
votes
2 answers

Builder Design Pattern - How to make field only accessible to one of its subtype

I have created a builder for client types A and B. Client TypeA has two fields fieldA and fieldB (see below), while client TypeB has two additional fields. How can I make sure field C and D are only accessible to client TypeB, i.e. client TypeA…
0
votes
1 answer

Enhancing Lombok's Builder with custom setter method and enhance the existing build method without reimplementation

I'm using Lombok's @Builder annotation and need to add a custom setter method, as well as enhancing the build() method. However, I'm stuck with two solutions where none covers both requirements at once and one contradicts the other. They vary…
Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136
0
votes
1 answer

How to combine Javas Builder pattern with Scala case class with optional fields?

In Scala you often use Java APIs which use the Builder pattern, e.g Google Maps Java Client (used in the example below). I use a Scala case class in our app to gather all values that I will use then for the Builder pattern of the Java API. I design…
Chris W.
  • 2,266
  • 20
  • 40
0
votes
0 answers

Possible flaw in Builder pattern?

Could someone explain, why do we need to have getResult() method? Why buildPart() has no return value? It seems like an unnecessary step which has no real benefit. Why would we call buildPart() it we don't need the result? I think it would be much…
RedFox
  • 1
  • 1
0
votes
1 answer

C# Step Builder with Required Field

I currently have a very basic Step Builder in a C# application that is created to allow all fields as optional and it is working fine for this (although this makes it not really a Step Builder). I know that required fields can be added to the…
TheLovelySausage
  • 3,838
  • 15
  • 56
  • 106
0
votes
1 answer

Change immutable builder constructor to use generics

I have a following class which is a basic DTO for child classes. I need to fix protected constructor because Intellij says: 'raw use of parameterized class builder'. Can someone please take a look and point how to re-write this constructor to…
badCoder
  • 730
  • 1
  • 5
  • 13
0
votes
1 answer

How to created builder for nested objects

I am looking for a way to create a builder that can create nested objects. I have already read this topic: Builder pattern with nested objects but that approach is modyfing model/entities which I'd like to avoid. I have few models: Advertisment has…
tylkonachwile
  • 2,025
  • 4
  • 16
  • 28
0
votes
1 answer

Java abstract Step Builder pattern

I am designing a java system where users can define some rules in a fluent style. Rules have many properties, which are partly mutually exclusive. We use a builder pattern with validation for this. To make the system easier to use, we want to…
HectorLector
  • 1,851
  • 1
  • 23
  • 33
0
votes
0 answers

Class inheriting Builder Pattern class with private constructor

Okay, so I have a parent class with Builder Pattern and private constructor: public class ExternalResult implements ExternalEntity { private String mConnectionStatus; private ResultSet mResultSet; /** * Creates a new instance…
0
votes
0 answers

Builder Pattern with abstract class

I am trying to learn and implement Builder Pattern using a Pizza example. I am trying to extend the solution I have to achieve 1 more thing: Users should be able to order a specific Pizza ( Hawaiin, Meat, Veggie ) with a little bit of customization…
kukroid
  • 420
  • 6
  • 15
0
votes
0 answers

How can I add a contact to DOM and array?

Hello dear developers, I have this code in builder pattern and I want to make a phone book , I want , when an user clicks on add button a contact would be added to DOM and push to records, I need the name and number would be given from user and I…
James
  • 5
  • 2
0
votes
1 answer

Is it compulsory for Parent class to use Builder pattern if Child class use Builder pattern?

I have came across a scenario in my project where I have decided to use Builder pattern for creating objects of one of my Java class that extends some other Class (Super class is Third party api - can't modify their code) so how to initialize parent…
Loren
  • 320
  • 1
  • 10
  • 25
0
votes
1 answer

How to write a overriding method which returns the instace of the calling class in Java

I am relatively new to Java and Design patterns. I am trying to implement the Builder pattern for my application. I have an interface which has a method build this build method will take the class as a parameter and return the same. public interface…
BATMAN_2008
  • 2,788
  • 3
  • 31
  • 98