Questions tagged [builder-pattern]
The builder-pattern tag has no summary.
61 questions
2
votes
1
answer
136
views
For N and NBuilder, should N be an instance variable of NBuilder, or all parameters of N be instance variables of NBuilder,finally new N() in build()?
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 ...
0
votes
0
answers
130
views
factory methods in JPA entity classes. anti pattern?
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 ...
5
votes
6
answers
2k
views
Is it a good idea to return a Builder from a Factory?
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 ...
0
votes
1
answer
133
views
API design question: Should a builder perform expensive validation when building?
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, ...
0
votes
1
answer
109
views
How to create QueryBuilder to work with concurrent requests
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 ...
2
votes
2
answers
147
views
Is the process of building a model from a dictionary necessarily the builder pattern?
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
...
3
votes
1
answer
248
views
GOF class diagram for Builder pattern appears to contradict its corresponding sequence diagram
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 ...
3
votes
3
answers
471
views
How to efficiently build objects without default constructors
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 ...
-1
votes
1
answer
218
views
How can I use builders for products with incompatible interfaces?
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 ...
1
vote
1
answer
717
views
Builder design pattern when creating object between many layers
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 ...
4
votes
2
answers
874
views
Is it a code smell to have two different implementations of the builder design pattern, for the same model?
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, ...
-1
votes
3
answers
293
views
Design pattern for creating and scheduling tests/exams
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 ...
5
votes
2
answers
431
views
GoF Builder Pattern Applicability
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 ...
1
vote
2
answers
1k
views
Is it wrong to extend an inner static class in java? (Builder pattern)
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 ...
2
votes
2
answers
955
views
Builder Pattern: Is there any advantage of having instance variables + product reference instead of just product reference?
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 ...