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

How can I exclude a property from a lombok builder only if the property is null

I have a user model class that looks like: @JsonSerialize @Getter @Setter @FieldDefaults(level = AccessLevel.PRIVATE) @Builder public class User { @Default String _dn = BASE_USER_DN; @Default String[] objectClass = {"top", "person",…
amadain
  • 2,724
  • 4
  • 37
  • 58
9
votes
2 answers

Rails 3/Cucumber problem: "...already activated builder 3.0.0, but your Gemfile requires builder 2.1.2"

I've been using cucumber without trouble for with Rails 3 for a while, but after a whole bunch of tinkering today (including gem cleanup), I get the following error whenever I run "cucumber features" You have already activated builder 3.0.0, but…
PlankTon
  • 12,443
  • 16
  • 84
  • 153
9
votes
1 answer

How to copy/transform an AutoValue object with builder

I'm playing auto-value with builder recently. And I'm in such a situation, say I have to transform an existing object to a new one with a few properties get updated. The example code is here: @AutoValue public abstract class SomeObject { public…
xinthink
  • 1,460
  • 1
  • 18
  • 22
9
votes
3 answers

Mapping an object to an immutable object with builder (using immutables annotation processor) in mapstruct

We are using the immutables framework to generate all DTOs. Now we would like to map these objects one to another with mapstruct. But the generated DTOs are immutable and have no setters and no constructor, corresponding to the builder pattern. They…
Marc von Renteln
  • 1,229
  • 15
  • 34
9
votes
2 answers

Builder pattern validation - Effective Java

In Item 2 of Effective Java (2nd Edition), the author mentions the following about imposing invariants on parameters while using Builders: It is critical that they be checked after copying the parameters from the builder to the object, and that…
Abhigyan Mehra
  • 215
  • 1
  • 4
  • 7
9
votes
2 answers

XCode Storyboard Localization Duplicate Strings Merge?

I am currently working on an iOS app and localizing it into multiple languages but have faced an annoying (not breaking) issue. When i would add a new localization for my storyboard xcode will automatically populate the strings, which is very nice.…
Guus
  • 399
  • 2
  • 15
9
votes
5 answers

Class with many parameters, beyond the Builder pattern

Context Suppose you have a component with a great many options to modify its behavior. Think a table of data with some sorting, filtering, paging, etc. The options could then be isFilterable, isSortable, defaultSortingKey, etc etc. Of course there…
vektor
  • 3,312
  • 8
  • 41
  • 71
9
votes
2 answers

Builder pattern with a Java 8 Stream

I am building an object with a simple loop: WebTarget target = getClient().target(u); for (Entry queryParam : queryParams.entrySet()) { target = target.queryParam(queryParam.getKey(), queryParam.getValue()); } I want to do the…
Francesco
  • 857
  • 1
  • 11
  • 26
9
votes
1 answer

Laravel 5 Migration, Invalid default value when integer

I was trying to create an table having a 0 as its default integer value The code looks like: Schema::create('gsd_proyecto', function($table) { $table->increments('id'); $table->string('nombre', 80)->unique(); …
WindSaber
  • 323
  • 1
  • 3
  • 15
9
votes
3 answers

How to insert editText number in AlertDialog Android

i have this problem. I have create a small app Android. I show a AlertDialog.Builder with EditText, so the user must click on the EdiText, select Number 123 then insert a int number. I would like to show a keyboard with only number. Can we Help me?…
bircastri
  • 2,169
  • 13
  • 50
  • 119
9
votes
5 answers

symfony 2.3 form getData doesn't work in subforms collections

I have a form which contains a collection. So I have: /* my type */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name') ->add('photos','collection',array( 'type'=> new PhotoType(), …
Angel
  • 1,970
  • 4
  • 21
  • 30
8
votes
4 answers

Rails+Builder.Generate XML output without entities

How to make Builder to not encode 'śćż' and other such characters. What I want is 'całość' to be literally printed in XML document. Example: xml.instruct! :xml, :version => '1.0', :encoding => 'utf-8' xml.Trader( :'xmlns:xsi' =>…
Casual Coder
  • 1,492
  • 2
  • 14
  • 15
8
votes
2 answers

Laravel, how to convert a collection object into a builder object

I need to use paginate and simplepaginate on a collection, so i'm trying to convert the collection into a builder object. To do so I am thinking of creating a function that gets the id of every item in the collection and then builds a query with it,…
Khaledman
  • 91
  • 1
  • 3
8
votes
2 answers

How to save ruby builder generated xml instead of rendering it in rails application?

I have a builder that renders xml when create is called. How can I skip the rendering step, but save the xml to the filesystem? def create @server = Server.new(params[:server]) respond_to do |format| if @server.save …
tom eustace
  • 1,241
  • 2
  • 13
  • 20
8
votes
3 answers

Comparison of Hudson, CDash, CruisonControl, TeamCity for Continuous Integration / Builder

I found most people talk about Hudson for simple and free continuous integration. Now personally I'm not fond of its interface which I find very messy, and I found almost no one talking about CDash -- I love CMake and CTest seem nice too. Could you…
Wernight
  • 36,122
  • 25
  • 118
  • 131