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
3 answers

Builder pattern. Initialization of duplicate parameters?

Suppose I have a car builder with parameters such as model, color and speed: public class Car { private String model; private int color; private int speed; public Car(String model, int color, int speed) { this.model =…
1
vote
1 answer

Is it possible to invoke a function with a unaryPlus in kotlin?

This is a followup question on another question I asked yesterday. How can I build a nested list using builder pattern? Credit to: Pelocho for giving nice answer. I used this Tutorial to do a type safe graphQL query builder: What I want to do now is…
mama
  • 2,046
  • 1
  • 7
  • 24
1
vote
1 answer

Is it possible to verify at compile time whether the required function is called for the Factory Class in Kotlin?

class ModelFactory { fun setA() : ModelFactory { // blabla... } fun setB() : ModelFactory { // blabla... } fun setC() : ModelFactory { // blabla... } fun build() : Model { // An error occurs…
H.Kim
  • 525
  • 4
  • 14
1
vote
2 answers

Lombok @NonNull annotation with @Builder not reflecting in test coverage

I have come across an issue while testing lombok annotated class. Description :- When we annotate a java class(POJO) with @Builder, and have certain instance variable with @NonNull constraints, while writing the test case to check for…
Radium Sharma
  • 11
  • 1
  • 5
1
vote
2 answers

About performance of builder pattern

In order to have tested more readable and easy to write I usually use the BuilderPattern in my value object. For example instead of writing this simple class in a standard way: public class MyClass{ private String myProperty; public void…
Renato
  • 2,077
  • 1
  • 11
  • 22
1
vote
1 answer

Implementation of Hierarchical Builder pattern

I am implementing Hierarchical Builder Pattern. I have used generics to make return type of my Parent Builder setter as that for child. Still I am facing problem when I use the child setter method after calling parent setter method. I don't want to…
coderzzz18
  • 2,535
  • 5
  • 16
  • 23
1
vote
1 answer

Python: Throw warning when class is instantiated outside builder

I have a class which constructor is getting overly complicated so I wanted to use a builder pattern to manage all the construction steps. The thing is an important part of the application depends on the old way of instantiating the class, so I can't…
Roäc
  • 149
  • 19
1
vote
0 answers

Is builder pattern required in this scenario?

Is builder pattern required here? I am writing a class which needs 3 parameters to start working. I am enforcing the object creation by passing an object which will have the 3 values. I validate the parameters via a method and the class looks…
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78
1
vote
1 answer

How can I improve readability of this Kotlin code?

I want to improve this code in Kotlin, it seems too redundant It should be possible with .forEach and Lambda's, but I don't know how Can anyone help please? val Point1 : List = topleft .split(",") .map { …
JetBrains
  • 456
  • 2
  • 6
  • 18
1
vote
1 answer

How to inherit in Builder Pattern in java

I want to inherit a class from a Parent class containing Builder class, but gives compilation error "default constructor not available" in parent class. I tried building a default constructor for parent class with null values. Yet the default…
1
vote
1 answer

Builder pattern in place of method overloading

I have an interface TaxCalculator that looks like this public interface TaxCalculator { int DEFAULT_AMOUNT_FOR_RATE_CALCULATION = 100; /** * * @param cart the cart to calculate taxes for. Right now we are only calculating using the total…
1
vote
1 answer

Unchecked conversion warning with generics

I don't quite understand, why my code has to do a unchecked conversion and how I can fix that. I am implementing immutable objects with the builder pattern for which I implemented the "Immutable" interface with the inner interface "Builder". Each…
Malte
  • 75
  • 7
1
vote
1 answer

Writing data classes with builder pattern

I have a data class which uses a builder to create the object and stores the data in a buffer in serialized form. I am planning to change the class to add and remove some fields. There are systems that will use both version of the class to create…
jigsaw
  • 165
  • 1
  • 16
1
vote
1 answer

Constructor runs once in multi-Instantiates of a class in "builder pattern" in react app

I have a class in my react app which uses 'Builder Pattern' and I've imported it in some nested components in my page. for example in parent component and child component, too. But it seems it calls the class's constructor once! and in second…
Pouya Jabbarisani
  • 1,084
  • 3
  • 16
  • 29
1
vote
0 answers

Is the Builder Pattern not available when updating(CRUD) in a spring boot? Can only be used to create objects(for constructor)?

I used Builder pattern. This is Entity class. @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Entity public class Posts extends BaseTimeEntity{ @Id @GeneratedValue private Long id; @Column(length = 500, nullable =…