Questions tagged [builder]

An object creation software design pattern, one of the Gang of Four's creational design patterns.

The Builder design pattern separates the construction of a complex object from its representation.

It has two common variations:

  • The pattern as outlined in the book "Design Patterns" by the "Gang of Four" (Gamma, Helm, et al) (an example can be found on the Wikipedia page)
  • The pattern as outlined in the book "Effective Java" by Joshua Bloch (Example)

The latter is in many ways a consolidation of the participants in the GoF pattern. For example, the director is typically the product, and there is typically no "abstract builder", only a single concrete builder.

Builder is usually very helpful in solving the problem of telescoping constructors by reducing the combinations of constructors required for optional construction-time fields.

This is one of the Gang of Four's creational , first published in Gamma et al.'s book "Design Patterns: Elements of Reusable Object-Oriented Software".

1895 questions
8
votes
2 answers

Java BuilderTestPattern - how to avoid boilerplate?

I have a lot of value objects in my project. I'm using project lombok to eliminate some boilerplate, so my value objects look like the following one: @Value @Accessors(fluent = true) public class ValueObject { private final String firstProp; …
slnowak
  • 1,839
  • 3
  • 23
  • 37
8
votes
1 answer

How to tell Builder to not to escape values

ruby-1.8.7-p249 > xml = Builder::XmlMarkup.new => ruby-1.8.7-p249 > xml.foo 'wow' => "<b>wow</b>" ruby-1.8.7-p249 > Builder is escaping the content and is converting the b tag into an escaped…
Nick Vanderbilt
  • 36,724
  • 29
  • 83
  • 106
8
votes
2 answers

Using the builder pattern in a for loop

So I came across some code that looks like this: Polygon polygon = Polygon.Builder() .addVertex(new Point(38.085255f, -122.734590f)) .addVertex(new Point(37.513400f, -122.726350f)) .addVertex(new…
whla
  • 739
  • 1
  • 12
  • 26
8
votes
5 answers

Design view disappeared from Interface Builder

All of a sudden, the visual design window disappeared from my Interface Builder. It is a regular UIView, has some UIImageView, UILabel, and UIButtons on it. When I open IB, I can see the document window (with File's Owner, First Responder and View…
skywalker168
  • 101
  • 1
  • 3
8
votes
2 answers

Builder Pattern inside vs outside class?

What are the advantages between using the builder pattern within vs outside the class? Inside class: public class Person { private String name; private String eyeColor; private String hairColor; public Person setName(String name) { …
Popcorn
  • 5,188
  • 12
  • 54
  • 87
8
votes
1 answer

Create new object with Builder pattern with "old" object reference

I am playing around with the Builder pattern and get stuck how to add a new "property" to a new-created object: public class MsProjectTaskData { private boolean isAlreadyTransfered; private String req; public static class Builder { …
sk2212
  • 1,688
  • 4
  • 23
  • 43
8
votes
3 answers

Flash Builder 4.7 commercial application - no design view

I have programmed a large, commercial level mobile application using Flash Builder 4.6. It is working GREAT when ran on both iOS and Android devices. I was using the trial version of Flash Builder 4.6 to develop this application. I used the…
Jesse Rallo
  • 163
  • 1
  • 2
  • 9
8
votes
8 answers

Clearing doubts about the builder pattern

I am learning about the builder pattern, and so far I understood that, it is a great alternative to the commonly patterns used for initialization: Telescoping Constructor Pattern JavaBean Pattern The thing is, I don't really like to remove the…
javing
  • 12,307
  • 35
  • 138
  • 211
8
votes
3 answers

Adding HTML to my RSS/Atom feed in Rails

The default rails XML builder escapes all HTML, so something like: atom_feed do |feed| @stories.each do |story| feed.entry story do |entry| entry.title story.title entry.content "foo" end end end will…
Shalmanese
  • 5,254
  • 10
  • 29
  • 41
7
votes
4 answers

Flash Builder cannot locate the required debugger version of Adobe Flash Player

I'm running Flash Builder 4, with Flex 4.5.1 (also have 4.1, 4.0 and 3.5) and I receive this error when I debug... C:\Windows\SysWOW64\Macromed\Flash\NPSWF32.dll Flash Builder cannot locate the required debugger version of Adobe Flash Player. You…
Jeanie Tallis
  • 595
  • 2
  • 6
  • 12
7
votes
3 answers

how to refresh ListView.builder flutter

How can I refresh my ListView.builder when adding item to the list? ListView.builder( itemCount: propList.length, scrollDirection: Axis.horizontal, shrinkWrap: true, itemBuilder: (context,index)=> Text(propList[index]), …
Husamuldeen
  • 439
  • 1
  • 8
  • 21
7
votes
1 answer

jOOQ: reusing / copying queries

In order to avoid re-creating the same part of a dynamic query over and over again, I was going to build the main part once and then reuse this part in different parts of the application. Since building the query is somewhat involved (see question…
Chris
  • 312
  • 1
  • 11
7
votes
2 answers

How to use Jackson to deserialize external Lombok builder class

I have a 3rd party Lombok builder POJO, one that I cannot modify, that I want to serialize using jackson. Notably it does not have a NoArgsConstructor. @Data @Builder public class ExternalClass { private String name; private String data; …
pscl
  • 3,322
  • 25
  • 29
7
votes
2 answers

Using Lombok to create builders for classes with required and optional attributes

Searching for a plugin to avoid boilerplate code to implement Joshua Bloch's builder pattern I found the amazing Lombok Project which enables you to generate builders via annotations like this: @Builder public class Person { private String…
Arash Kamangir
  • 293
  • 3
  • 7
7
votes
3 answers

Spliterator vs Stream.Builder

I read some questions how to create a finite Stream ( Finite generated Stream in Java - how to create one?, How do streams stop?). The answers suggested to implement a Spliterator. The Spliterator would implement the logic how to and which element…
LuCio
  • 5,055
  • 2
  • 18
  • 34