Skip to main content

All 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 ...
wcminipgasker2023's user avatar
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 ...
CuriousGuy's user avatar
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 ...
user32882's user avatar
  • 267
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 ...
Patrick Wright's user avatar
-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 ...
JS Lavertu's user avatar
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 ...
Draeggiar's user avatar
-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 ...
Amal K's user avatar
  • 111
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 ...
Nishant Ingle's user avatar
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 ...
user3760100's user avatar
1 vote
1 answer
81 views

Can a GoF Builder implementation be considered valid without an explicit getProduct()?

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
7 votes
3 answers
6k views

Design pattern: How to inject dependencies into a Command pattern

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

Builder Pattern: Is it acceptable to use "passing-by-reference" on Director methods?

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
0 votes
3 answers
4k views

Builder Pattern - Must it be part of The same Class?

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

Creational design pattern that allows configuration of objects

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
650 views

how to use Builder pattern combined with protected access modifier?

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

15 30 50 per page