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

How does mongoose (Builder pattern) chained methods work under the hood

The question is more on the mongoose implementation of chained methods than actually mongo queries. I am working n a plugin implementation for which I need to provide custom methods like populate, count, etc. shown below. a.find({ b: 'thing'…
kgangadhar
  • 4,886
  • 5
  • 36
  • 54
0
votes
1 answer

How can I build a nested list using builder pattern?

I am trying to make a query builder for GraphQL syntax, by using a builder pattern. I already did it for the filtering part: I want to programatically make a way to say what data I want to get back from the query. (NOTE: before the title part of the…
mama
  • 2,046
  • 1
  • 7
  • 24
0
votes
0 answers

Spring boot builder pattern entity to dto

I'm creating an API that transmits data from another web service. I'm looking for good practice to convert the objects from the web service to my DTO's. The conversion from the object to DTO has some logic. I have now implemented this…
0
votes
0 answers

Using Kotlin to build classes with Generic data types

I'm in the process of building my Kotlin and general programming knowledge and trying to follow good practices while doing so. I am working on a project with some important matrix manipulation so I decided I would build my own Matrix class and…
0
votes
1 answer

How do I simplify all of these query parameter possible combinations in Kotlin? Builder Pattern?

I'm building an Android App with Kotlin that uses various NYTimes APIs to fetch different news data.. Here I have a search screen where I want the user to be able to enter a search query (i.e. "Japan") and check off any checkbox and they will even…
Cosovic
  • 79
  • 6
0
votes
1 answer

How to implement a builder for a complex type?

I have a very complex type. The type has multiple readonly properties and each property is a complex type: public class FinalResult { public ComplexType1 ComplexType1 {get;set;} public ComplexType2 ComplexType2 {get;set;} public…
Martijn
  • 24,441
  • 60
  • 174
  • 261
0
votes
1 answer

How to implement a checked builder pattern in Java

I'm trying to implement a checked builder pattern similar to how it's described in this: https://dev.to/schreiber_chris/creating-complex-objects-using-checked-builder-pattern The result I'm trying to reach is as follows: Builder builder = new…
fehays
  • 3,147
  • 1
  • 24
  • 43
0
votes
1 answer

Can I combine the builder pattern with a lambda expression?

The following lambda expression operates on a class which was created outside of the lambda. I consider this clumsy. Is there a better way to this? class Builder { var searchTerms = listOf() fun build(whatever: String): Builder { …
0
votes
0 answers

Mocking a method present in outer class of a builder pattern (Unit test)

I am trying to figure out a way to mock the method inside the following builder for my unit test. public class A { private C ObjectC; private D ObjectD; public getObjectC() { // This should not be executed in Unit test as object…
0
votes
2 answers

Javascript Builder Pattern Not Seeing Declared Varialble

I'm trying to implement the Builder Pattern to generate a JSON string of options that are passed into a library to generate widgets. I can't understand why at console.log below that this.options is undefined. let Options = function(options) { …
SweetTomato
  • 509
  • 1
  • 6
  • 16
0
votes
0 answers

Java for loop printing only 1st value- BuilderPattern

I am trying to experiment and learn BuilderPattern,reading from json file at the same time. My goal is to create object using the data I get from the json file. This is how the json file looks like: [{ "firstName": "Git", …
Sheikh Rahman
  • 895
  • 3
  • 14
  • 29
0
votes
0 answers

Extending Builder Class

I want to implement a design pattern where I setup a base builder class (BaseBuilder.java) that several other builder classes extend. The base builder class is abstract, and it contains values that are common to the other builders. Each builder…
portfoliobuilder
  • 7,556
  • 14
  • 76
  • 136
0
votes
1 answer

How to implement builder pattern when class is extending Abstract class

Trying to implement Builder pattern where I have a class Contract extending an abstract class service input I have created Contract Builder as added below, not getting how can I access userInfo of ServiceInput. *Can not modify ServiceInput class as…
Neeti
  • 377
  • 1
  • 4
  • 16
0
votes
1 answer

What issues (if any) do you see in using the builder-pattern within an entity itself as opposed to a separate inner class?

After searching SOF for related questions and finding something roughly similar for PHP, but still not satisfying, here's my question. Problem: using an inner static builder class feels like too much typing. I want to keep some properties immutable…
0
votes
1 answer

how to new an unknown object in abstract class

I would like to use a builder pattern to create an unknown object how to do that? my code like this: public abstract class abstractA>{ public static class Builder { private JPanel panel = new JPanel(); …
Shawn Plus
  • 457
  • 1
  • 6
  • 15