Jump to content

Talk:Builder pattern

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nobnak (talk | contribs) at 01:58, 3 September 2010 (Class data members should be private, chefs create pizza). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
WikiProject iconJava Start‑class Low‑importance
WikiProject iconThis article is within the scope of WikiProject Java, a collaborative effort to improve the coverage of Java on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
LowThis article has been rated as Low-importance on the project's importance scale.
Note icon
This article has been automatically rated by a bot or other tool because one or more other projects use this class. Please ensure the assessment is correct before removing the |auto= parameter.
WikiProject iconComputer science Start‑class
WikiProject iconThis article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
???This article has not yet received a rating on the project's importance scale.
Things you can help WikiProject Computer science with:

Builders and immutable objects

A major benefit of builders is that they can be used to create immutable objects without complex constructors. In Java, the builder pattern also simulates named constructor parameters:

public final class Pizza {
    private final String dough;
    private final String sauce;
    private final String topping;

    private Pizza(Builder builder) {
        dough = builder.dough;
        sauce = builder.sauce;
        topping = builder.topping;
    }

    public static class Builder {
        private String dough;
        private String sauce;
        private String topping;

        public Builder dough(String dough) {
            this.dough = dough; 
            return this;
        }
        public Builder sauce(String sauce) {
            this.sauce = sauce; 
            return this;
        }
        public Builder topping(String topping) {
            this.topping = topping;
            return this;
        }

        public Pizza create() {
            return new Pizza(dough, sauce, topping);
        }
    }
}
 
/** A customer ordering a pizza. */
class BuilderExample {
    public static void main(String[] args) {
        Pizza hawaiian = new PizzaBuilder()
             .dough("cross")
             .sauce("mild")
             .topping("ham+pineapple")
             .create();
    }
}

Abstract Builder class

In the diagram, the Builder should be italicized to indicate that it is an Abstract class. If it is an interface rather than abstract class (alá Java), then it would be better served with an <<interface>> stereotype. —Preceding unsigned comment added by 71.57.242.240 (talk) 22:06, 12 February 2008 (UTC)[reply]

Correspondance between the sequence diagram and the Java program

The Sequence diagram dosen't seems to correspond to the example in Java any toughts ? --Khalid hassani 11:15, 11 August 2006 (UTC)[reply]

Adding a section about the difference between Factory Method pattern and Builder pattern

Many people especially beginners are confused about the difference between those two patterns, as they seem very similar, we need to add a section about the difference between the two patterns, the google groups discussion in the External links section seems a good starting point to me.--Khalid hassani 11:19, 11 August 2006 (UTC)[reply]

Class data members should be private, chefs create pizza

The abstract class PizzaBuilder should not have a protected Pizza data member this should be private. Having protected data creates fragile class hierarchies and generally should be avoided. Also a minor point, but generally chefs do the cooking not waiters!

Yeah, I think the Java example should be refactored. Nobnak (talk) 01:58, 3 September 2010 (UTC)[reply]

Ambiguity? Or am I just confused...

The explanation for the Director class is: "The Director class is responsible for managing the correct sequence of object creation. It receives a Concrete Builder as a parameter and executes the necessary operations on it."

Under the "Difference Between Builder pattern and Abstract factory pattern" heading, this is mentioned: "...the client just requests a configuration and the builder directs the logic of building it"

This seems to say that the Builder manages "the correct sequence of object creation". Is the client the "Director" or is the builder the "Director"? —The preceding unsigned comment was added by 61.14.96.7 (talk) 07:51, 30 April 2007 (UTC).[reply]

Missing the Mark

Previous commentor: You're not confused. The author of this article is deeply confused about the Builder pattern. The sample cited in the first comment above better represents what a Builder is. —Preceding unsigned comment added by Jdmarshall (talkcontribs) 23:19, 17 December 2007 (UTC)[reply]

Yeah, this article is totally duff. Where do we get these guys? -- TomAnderson —Preceding unsigned comment added by 128.40.81.110 (talk) 18:24, 12 May 2008 (UTC)[reply]

Most of this page is copied

Most of the text for this page is copied directly from http://sourcemaking.com/design_patterns/builder in violation of its license terms. That work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License. This page does not attribute the work to its original author.

Vaughanje (talk) 19:51, 12 May 2008 (UTC)[reply]

Sorry, I don't see the similarity. The only part that is similar is the introductory sentence, which both authors seem to have lifted verbatim from the GoF book, and the secondary concepts, which also, you guessed it, come from the GoF book. Jdmarshall (talk) 11:58, 18 May 2008 (UTC)[reply]

Class diagram glitch

The Builder in the class diagram is not an <<interface>>, but it should be (also for the sake of calling the other class ConcreteBuilder). --78.43.87.113 (talk) 14:49, 7 August 2008 (UTC)[reply]


Example more like Abstract-factory

The example given leans more towards abstract factory. As mentioned, Builder is best used for building up Composites. So, Menu Items in menu system, or Genealogy tree of parents and children. Builders can use factories, and often do. This is why the example is confusing. It is attempting to use factories and be a builder at the same time. An improvement to the example would be to have a PizzaFactory, a SoftDrinkFactory and SideOrderFactory. Then, create an OrderBuilder that would build up an order using these factories. I'm not saying that this is the best example, but much clearer than what is there now. A simpler example, like building up a MenuSystem for an application, would be much clearer. —Preceding unsigned comment added by Hosick (talkcontribs) 07:44, 17 May 2009 (UTC)[reply]