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
2
votes
1 answer

Should a Test Data Builder construct defaults for it's non-primitives?

I've created a data builder in order to create test data in my unit tests. My data builders create defaults for all properties so that the tests that use them only need to specify the properties that are applicable to the test. Consider the…
mezoid
  • 28,090
  • 37
  • 107
  • 148
2
votes
3 answers

Python, combine long builder path and comments

Possible Duplicate: How to break a line of chained methods in Python? Following question is about python codestyle and may be design of reusable lib. So I have builder that chains graph creation into single big line as follow: graph.builder() \ …
Dewfy
  • 23,277
  • 13
  • 73
  • 121
2
votes
0 answers

Build nested or hierarchical object graphs in C#

I have an object hierarchy that can be represented simplistically like: public class ChannelEntity { ... public properties .... public FramesetEntity Frameset { get; set; } } public class FramesetEntity { ... public properties .... …
koder
  • 887
  • 9
  • 29
1
vote
1 answer

Inheritance with Builder pattern

Let's assume, that we have AbstractBufferBuilder class that contains some common methods for building some Buffer classes: class AbstractBufferBuilder { public: AbstractBufferBuilder &setBufferData(...) { //some code return…
AlexusXX
  • 15
  • 4
1
vote
1 answer

Trying to resolve builder-pattern from java to apex

`I've been studying a builder pattern and run into a problem during writing a code from Java to Apex. It works on Java, but something goes wrong on Apex Here's my Apex - classes. `public class Chiller { private double coolingCapacity; …
1
vote
0 answers

How to share a builder class across multiple instances in swift

I am trying to become a better developer and just started to study and use software patterns in small test projects. In my current project I focused on the builder pattern. Basically all I have is an App with two Views (Storyboards), A single…
bkDev
  • 66
  • 5
1
vote
2 answers

initialize a class loading data from file. is it a builder?

I am a newbie in design patterns. I want to create an instance of a class, say ClassA, and set some of its fields to the values read from a config file. If I keep distinct the code of the class from the code that manages the file with the values…
AgostinoX
  • 7,477
  • 20
  • 77
  • 137
1
vote
3 answers

Implementing Fluent Builder Pattern for nested clases

I am trying to understand fluent builder patterns and in my case, I have an object that has child objects too. Most of the online examples are based on a single object. There are some examples for nested objects but they all are different. So I am…
Ash
  • 447
  • 2
  • 6
  • 19
1
vote
1 answer

Using Builder Pattern, I got AttributeError: 'NoneType' object has no attribute to builder class function

I try to instance my class that made by using builder pattern class Cat: def __init__(self,height,weight, color): self.height = height self.weight = weight self.color = color def print(self): print("%d %d %s"…
Minseo Kim
  • 13
  • 3
1
vote
1 answer

HP OOP builder pattern use

I'm confused about using PHP Builder pattern in practise. In many documentation they propose using the Builder like this. require 'Pizza.php'; require 'PizzaBuiler.php'; $piza_builder=(new PizzaBuilder('medium')) ->cheeze(true) …
1
vote
2 answers

Builder pattern that requires at least two properties to be specified

I am writing a RequestBuilder class, which will handle the creation of a query string, based on the following criteria category (String) country (String) keywords (String[]) page (int) pageSize (int) Since not all criteria are mandatory and there…
Kotaka Danski
  • 451
  • 1
  • 4
  • 14
1
vote
1 answer

Avoid invoking multiple constructors when using the builder pattern in c++

Consider the following piece of code: CodeBuilder code = CodeBuilder{"Dog"}.add_field("name", "std::string").add_field("legs", "int"); and the following implementation: class CodeBuilder { MyString _code; public: CodeBuilder(const…
DeSpeaker
  • 1,159
  • 1
  • 11
  • 11
1
vote
1 answer

Builder pattern with infix for Coroutines

I am trying to write a class to easily chain code run in different coroutine contexts. Ideally, I would like to use it like this: io { // Run IO code that returns an object (nullable) } ui { ioResult-> // Run…
JonZarate
  • 841
  • 6
  • 28
1
vote
1 answer

How to create multiple varieties of a Class using the Builder Pattern?

My goal is to use the Builder Pattern to create the Product Details' field based on the product category. Regardless of the product category, this is the basic ProductDetails attributes. int stock; // required String ships_from; //…
Jason Rich Darmawan
  • 1,607
  • 3
  • 14
  • 31
1
vote
0 answers

Method chaining to build an object which having another object via Lombok Builder on both objects

I have Person class that has a reference type field of its inner class Address. When instantiate a Person object I want to use method-chaining tactic and builder pattern via Lombok's @Builder like below. class PersonTest { @Test void…
Kiwon Seo
  • 69
  • 5