Skip to main content

Questions tagged [builder-pattern]

Filter by
Sorted by
Tagged with
2 votes
1 answer
159 views

As far as I know about builder pattern, for example, an object, Student: public class Student{ private String name; private int age; //setter and getter } to apply builder pattern to ...
wcminipgasker2023's user avatar
0 votes
0 answers
172 views

I started using factory methods in JPA Entity classes. But I'm not sure if it's an anti-pattern. If it is , then where do I place them instead ? A similar sample is below @Builder @Entity Class ...
kommradHomer's user avatar
5 votes
6 answers
3k views

I would want to have a builder for creating a complex object, for example Employee. I would want to be able to create my objects in two ways: Case 1. Get Employee with default values Case 2. Get ...
CuriousGuy's user avatar
0 votes
1 answer
163 views

I'm working on a library of C++ wrappers/bindings, for another, C-ish, API. The C'ish API has a "launch" function, which, among other things, takes a launch configuration structure (well, ...
einpoklum's user avatar
  • 2,808
0 votes
1 answer
143 views

I need assistance with the QueryBuilder that generates OData query. Following is my implementation and it approach has couple of issues If user forgets to SetRootTable then it will cause serious ...
Sunny's user avatar
  • 945
2 votes
2 answers
172 views

I am working on a tool that scrubs Do-Not-Call (DNC) phone records from a skip-traced CSV file. I have this PhoneModel for child phone entries for each row. It consist of the following fields: isDNC ...
Mike Warren's user avatar
4 votes
1 answer
290 views

In the Design Patterns: Elements of Reusable Object Oriented Software, the Gang of Four present the following canonical form for the Builder pattern: In Appendix B the following is mentioned ...
user32882's user avatar
  • 277
3 votes
3 answers
592 views

I am trying to explain and understand a way to create object which cannot have "default" instances. Typically I want classes which represent, as closely as possible, the real-life concept I ...
Patrick Wright's user avatar
-1 votes
1 answer
251 views

I am working on a program to automatically design heater units based on varying client specifications. The process for creating each heater is quite involved and requires multiple optional steps ...
JS Lavertu's user avatar
1 vote
1 answer
799 views

I stumbled on following problem, and I'm curious if it could be done better. A while ago I wrote a factory class that looked something like this: public class Foo { private IDbContext ...
Draeggiar's user avatar
4 votes
2 answers
953 views

Shoutout to David Arno for teaching me about the builder design pattern via this thread! I have since used that pattern althroughout the code base to abstract out creating models from data stores, ...
Mike Warren's user avatar
-1 votes
3 answers
331 views

I have an Exam class that represents an examination/test: public class Exam { public int Id { get; set; } [Required] [StringLength(maximumLength: 30, MinimumLength = 1] public string ...
Amal K's user avatar
  • 111
5 votes
2 answers
487 views

The book Design Patterns: Elements of Reusable Object-Oriented Software says to use the builder pattern when The algorithm for creating a complex object should be independent of the parts that make ...
Nishant Ingle's user avatar
1 vote
2 answers
1k views

I'm working on a java project for the university. The project is a card game in which you travel around a 2D map and fight against some enemies. My part consists of creating the deck and the cards. I ...
Matteo Paolucci's user avatar
2 votes
2 answers
1k views

Consider the product class: class Car { private String color; private String model_num; //getters and setters for the above fields } Consider builder class 1: class CarBuilder1 { private ...
user3760100's user avatar
1 vote
1 answer
101 views

For studying purpose, I've tried to create a simple PHP implementation of Builder GoF (not the Joshua Bloch's one) inspired on this slide. The main goal of this example is to encapsulate the ...
celsowm's user avatar
  • 253
0 votes
1 answer
347 views

I have these classes and I want to instantiate each one of them easily. All the data to create them are in a json file and there will be a lot of different objects in the end. Each objects have a lot ...
rXp's user avatar
  • 117
7 votes
3 answers
7k views

I am pretty new to programming languages and only have limited knowledge about design patterns, so I hope you can help me with the following problem: I have an application that operates on a group of ...
Martin's user avatar
  • 91
2 votes
2 answers
3k views

For teaching purposes, I am trying to create a PHP implementation of a conceptual example of Builder Pattern: First of all, some products: class Product1 { private string $attribute1; ...
celsowm's user avatar
  • 253
1 vote
1 answer
315 views

Out of 5 creational design, would Builder and Prototype mixture be a valid use? The reason for this question is - Builder assists building complex objects with various combinations of attributes. But ...
ha9u63a7's user avatar
  • 397
0 votes
3 answers
4k views

For complex object creation, I am quite fond of Builder Pattern. My 1st question is "Do I need the Builder to be inside my complex class blueprint, or Could I actually have it outside?" e.g. Are the ...
ha9u63a7's user avatar
  • 397
2 votes
2 answers
2k views

With the factory pattern we abstract the creation of objects. But what if we need a specific configuration of an object that depends on the calling context? Example: So I have a Builder pattern for ...
Jim's user avatar
  • 359
0 votes
1 answer
673 views

I'm reading a book in Design Patterns, and below is some code example used by the author. The author tries to build a html builder as (code in C#): public class HtmlElement { public string Name, ...
slowjams's user avatar
  • 127
2 votes
2 answers
369 views

I'm working on a text GUI library which comes with builders for UI components (Buttons, Panels, etc). I have a base class for these builders which I'd like to redesign so that meaningless component ...
Adam Arold's user avatar
  • 1,190
0 votes
0 answers
124 views

I am trying to polish my data-mapping library and struggle with my fluent API design as it feels clumsy in some basic use-cases. The library focuses on defining mapping objects from one type into ...
roookeee's user avatar
  • 197
0 votes
2 answers
785 views

I read through a code example on github and instead of initializing the object using a constructor, they made every setter return the object itself to call it over and over again See, constructors ...
HashTableView's user avatar
2 votes
4 answers
9k views

A language agnostic approach since I see this problem in both compiled and interpreted languages with the builder pattern. Let's say I have a Model that has 10 required fields and 5 optional fields. ...
Devon's user avatar
  • 139
37 votes
9 answers
18k views

I have seen many implementations of the Builder pattern (mainly in Java). All of them have an entity class (let's say a Person class), and a builder class PersonBuilder. The builder "stacks" a variety ...
bhk's user avatar
  • 483
6 votes
1 answer
1k views

I'm struggling with the design in a WPF MVVM application. In a few courses I've taken, they say that having a lot of parameters in a constructor is a code smell, but they never address how to deal ...
Adam's user avatar
  • 169
1 vote
1 answer
4k views

I like using the Builder/Director pattern to build complex objects. It works really well. The only restrictions (maybe it is not really a restrictions) I see is that all of the parameters for the ...
ColdAir's user avatar
  • 21
2 votes
2 answers
2k views

I've looked at various definitions of the builder pattern and whilst there's varying definitions, they tend to be focused on the broad definition of incremental construction. However, it seems that ...
Kevin Raoofi's user avatar
2 votes
1 answer
207 views

The question sounds retrograde but I have about 50 variables being passed to a class. Basically an array of data I call 'filters' that is first passed to a prepFiltersMethod($filters). This prep ...
Mike Q's user avatar
  • 135
1 vote
1 answer
115 views

Would it make sense for me to use a builder pattern to return data from an API? Currently I'm just creating the array structure and returning it. In more detail, I have 3 exit places for my class that ...
Mike Q's user avatar
  • 135
7 votes
3 answers
8k views

I asked a question on StackOverflow regarding how to 'best' use the Builder pattern for constructing a Value Object which could be constructed with or without optional parameters. One answer stated ...
Peppermintology's user avatar
1 vote
1 answer
219 views

Thinking about the overall architecture of the application logic: Current status: The model contains all resources that are used at runtime. In a factory you register a builder which is used to ...
user2366975's user avatar
2 votes
2 answers
9k views

What is an empty method and how are they used? I was reading a documented about the BUILDER Pattern and I got a curious about how it is implemented in C++. The author defines that in C++ could be ...
Diego Alejandro Parra Guzman's user avatar
2 votes
1 answer
7k views

Let's say I have a class Dot with a builder: public class Dot { private final Double x; private final Double y; private final Color color; private Dot(Double x, Double y, Color color)...
AplusKminus's user avatar
3 votes
3 answers
3k views

I have a large class with complex properties. I'd like to introduce a default implementation, allow the user to override part of the default implementation and also make sure the user calls a sync ...
BornToCode's user avatar
  • 1,283
5 votes
3 answers
2k views

I see this sometimes: class SomeClass { Object param1, param2, param3, param4; private SomeClass(){} static class Builder { SomeClass someClassInstance = new SomeClass(); // ...
owl777's user avatar
  • 61
3 votes
1 answer
5k views

I've run into several situations where a POJO where whether a field value is meaningful depends on the value of another field. An example, using Lombok (which we try to use to avoid boilerplate): @...
ajb's user avatar
  • 131
7 votes
4 answers
9k views

I am currently learning about various object oriented design patterns. I came across a pattern called the builder pattern which is basically where you build a complex object through the use of ...
SteelToe's user avatar
  • 1,599
5 votes
1 answer
15k views

I have an object Carconstructed using builder pattern. Issue was a lot of code redundancy. Car.Builder builder = new Car.Builder("Mercedes"); builder.numDoors(carConfig.getNumDoors() ...
JavaDeveloper's user avatar
3 votes
1 answer
276 views

At work we have an interface that is getting bloated. The interface is designed to be easily implemented by an immutable object. So it looks something like this: //there is no behavior here, just ...
Ivan's user avatar
  • 575
12 votes
3 answers
5k views

In Java and C#, you can create an object with properties that can be set at initialisation by either defining a constructor with parameters, defining each property after constructing the object, or ...
svbnet's user avatar
  • 231
8 votes
3 answers
3k views

Often I see the implementation of the builder pattern (in Java) to be like this: public class Foo { private Foo(FooBuilder builder) { // get alle the parameters from the builder and apply ...
Andy's user avatar
  • 1,325
5 votes
1 answer
2k views

I'm trying to understand builder pattern usages and so to call to separate is usage types in groups. Here is what I discovered: Builder can be used to provide immutability (avoiding telescoping) for ...
Ivan Nikolaychuk's user avatar
11 votes
4 answers
6k views

Edit: I'd like to point out that this question describes a theoretical problem, and I am aware that I can use constructor arguments for mandatory parameters, or throw a runtime exception if the API is ...
derabbink's user avatar
  • 210
14 votes
5 answers
11k views

I have a fairly complex immutable data type that I'm using a builder object to instantiate. Currently, I have a setup where I parse a file, setting various fields in my builder, and then build the ...
codebreaker's user avatar
  • 1,764
23 votes
5 answers
2k views

I've recently deleted a java answer of mine on Code Review, that started like this: private Person(PersonBuilder builder) { Stop. Red flag. A PersonBuilder would build a Person; it knows about a ...
Mathieu Guindon's user avatar
22 votes
8 answers
5k views

Our codebase is old and new programmers, like myself, quickly learn to do it the way it's done for the sake of uniformity. Thinking that we have to start somewhere, I took it upon myself to refactor a ...
rath's user avatar
  • 886