Does the Builder pattern really need a Director?

A Builder knows how to construct the various parts of an aggregate, while a Director knows the order in which they should be constructed. Wikipedia illustrates this pattern with a PizzaBuilder example:
http://en.wikipedia.org/wiki/Builder_pattern
I find it difficult to understand why one would not move the constructPizza() method (including its implementation) of Waiter (the Director) to PizzaBuilder (the abstract Builder), bypassing Waiter altogether:
PizzaBuilder hawaiianPizzaBuilder = new HawaiianPizzaBuilder();
hawaiianPizzaBuilder.constructPizza();
Pizza pizza = hawaiianPizzaBuilder.getPizza();Why is it so important to separate the how from the order? To me it looks like having a separate Director class makes things just more complicated without having real benefits.

Thank you for your reply. Are you suggesting that
real-world applications have several Directors that
differ in the order of construction? I just got
myself the GoF book and it speaks about just one
Director, which repeats the same construction
process, independent of the concrete builder passed
to it.If you look at the Consequences, list item 2 it states:
"..then different Directors can reuse it to build Product variants from the same set of parts. In the earlier RTF example, we could define a reader for a format other than RTF, say, an SGMLReader, and use the same TextConverters..."
Note that in the example the Reader is the Director and the TextConverter is the Builder.
The point of this pattern is to separate the code that knows what to do and the code that knows how to do it so that they can be combined indpendently.
Suppose you were writing a tool that could take XML or database rows and create a Swing GUI. Let's say you are also asked to take that XML and those database rows and create a web page.
If you combine the code that reads the input with the code that reads the output, you end up writing the xml reader twice, the database reader twice, the swing builder twice, and the web page builder twice. Then consider what happens if you need a third input format or more output formats.
I was thinking of using this pattern to create a
custom JTree in subsequent steps: 1) create the nodes
from a database, 2) create the tree model, 3) create
the tree. Right now everything happens in my JTree
constructor, which doesn't feel right since it's just
a GUI component. Would that be appropriate? I only
have one concrete builder now, so it seems a bit too
much.I would remove any knowledge of the database from your gui component. This doesn't require more code and it won't make things more complicated. I think you'll find that once you have done it, it will make things a lot easier to understand and work on. The idea that every Object should have a single responsibility is poorly defined but is, in my opinion, a very good way to think about your designs.

Similar Messages

  • Does the iPhone 5 really need a case?

    Does the iPhone 5 really need a case? ive been reading articles that says it doesn't, opinions please...

    In that case (no pun intended), you may not need one. I agree, it does look and feel better without the case.  I bought a clear case so it still shows off the design, but the problem is the case itself scratches easily.
    It's your call. But I would say, if you are not worried about dropping the phone (with AppleCare+, a replacement is only $49 as you may know), you do not absolutely need a case.

  • What the iPod touch really needs.

    So I may have missed a thread on this... But does it not seem logical that what the the iPod touch really needs bluetooth. I could care less about using bluetooth for audio, synking or anything else but 1 thing...
    Given that the iPhone is locked into AT&T wouldn't a bluetooth enabled pone allow you to use bluetooth's networking abilities to share you cell phones data plan? Granted some wireless providers (cough*verizon*cough) cripple there phones and disable this feature. but it would be at least an option to some people.

    The ipod touch does not support bluetooth nor does it have bluetooth built into the device. THere are bluetooth adapters that you might use for like headphones but nothing like data transfer and what you mention. If this is a feature you would like on a future ipod then leave your feedback at the link below.
    http://www.apple.com/feedback/ipod.html
    THese forums are for technical questions regarding the ipod touch and not for speculation or rumors. You should go elsewhere for such a thing. If your interested in how bluetooth works on the iphone then it is best to post your question about that product in the right forum linked below.
    http://discussions.apple.com/forum.jspa?forumID=1139
    GFF

  • Trying to implement the Builder pattern with inheritance

    This is just a bit long, but don't worry, it's very understandable.
    I'm applying the Builder pattern found in Effective Java (J. Bloch). The pattern is avaiable right here :
    http://books.google.fr/books?id=ka2VUBqHiWkC&lpg=PA15&ots=yXGmIjr3M2&dq=nutritionfacts%20builder%20java&pg=PA14
    My issue is due to the fact that I have to implement that pattern on an abstract class and its extensions. I have declared a Builder inside the base class, and the extensions specify their own extension of the base's Builder.
    The abstract base class is roughly this :
    public abstract class Effect extends Trigger implements Cloneable {
        protected Ability parent_ability;
        protected Targetable target;
        protected EffectBinder binder;
        protected Effect(){
        protected Effect(EffectBuilder parBuilder){
            parent_ability = parBuilder.parent_ability;
            target = parBuilder.target;
            binder = parBuilder.binder;
        public static class EffectBuilder {
            protected Ability parent_ability;
            protected Targetable target;
            protected EffectBinder binder;
            protected EffectBuilder() {}
            public EffectBuilder(Ability parParentAbility) {
                parent_ability = parParentAbility;
            public EffectBuilder target(Targetable parTarget)
            { target = parTarget; return this; }
            public EffectBuilder binder(EffectBinder parBinder)
            { binder = parBinder ; return this; }
        // etc.
    }And the following is one of its implementation :
    public class GainGoldEffect extends Effect {
        private int gold_gain;
        public GainGoldEffect(GainGoldEffectBuilder parBuilder) {
            super(parBuilder);
            gold_gain = parBuilder.gold_gain;
        public class GainGoldEffectBuilder extends EffectBuilder {
            private int gold_gain;
            public GainGoldEffectBuilder(int parGoldGain, Ability parParentAbility) {
                this.gold_gain = parGoldGain;
                super.parent_ability = parParentAbility;
            public GainGoldEffectBuilder goldGain(int parGoldGain)
            { gold_gain = parGoldGain; return this; }
            public GainGoldEffect build() {
                return new GainGoldEffect(this);
        // etc.
    }Effect requires 1 parameter to be correctly instantiated (parent_ability), and 2 others that are optional (target and binder). Implementing the Builder Pattern means that I won't have to rewrite specific construcors that cover all the combination of parameters of the Effect base class, plus their own parameter as an extension. I expect the gain to be quite huge, as there will be at least a hundred of Effects in this API.
    But... in the case of these 2 classes, when I'm trying to create the a GoldGainEffect like this :
    new GainGoldEffect.GainGoldEffectBuilder(1 , locAbility).goldGain(5);the compiler says "GainGoldEffect is not an enclosing class". Is there something wrong with the way I'm trying to extend the base Builder ?
    I need your help to understand this and find a solution.
    Thank you for reading.

    The GainGoldEffectBuilder class must be static.
    Otherwise a Builder would require a GainGoldEffect object to exist, which is backwards.

  • I made a bootable disc on an external hard drive, with Yosemite on it.  I am running Snow Leopard on my iMac.  How can I open the Yosemite disc from the desktop on my iMac?  Does the external hard drive need to be connected to my iMac by firewire to

    I made a bootable disc on an external hard drive, with Yosemite on it.  I am running Snow Leopard on my iMac.  How can I open the Yosemite disc from the desktop on my iMac?  Does the external hard drive need to be connected to my iMac by firewire to do that?

    kahjot wrote:
    Snow Leopard's Startup Disk pref can’t see Yosemite volumes. So the only way to switch from Snow Leopard to Yosemite is to do what Niel mentioned. Doesn't matter whether it's connected by USB or Firewire, although performance via FW would be faster.
    Are you saying that Yos/10.10, as a volume located in a mounted external drive won't appear as an option in Snow Leopard's Startup Disc, in Sys Prefs? I've never heard this one before. AFAIK any mounted volume, regardless of OS, should appear there. I would think that, if it appears in the Boot Picker/Startup Manager it would also appear and could be booted to from Snow's Startup Disk. I can't test this myself, since I don't have Yos. Is what you are saying documented somewhere?

  • What does the word "static" really mean?

    Yep, that's the question. What does the word "static" really mean?
    /Martin

    hi static means that u can use it with out creating an object of this class
    i.e. Class.Staticmethod()
    e.g. Math.pow(7,2)
    non static means u hava to create an object to use it
    like ClassObject.method()
    and remember it doesn't fit only for methods it fits for all members of a class i.e. methods and variables

  • WRT54GC - Does the DHCP Server really work?

    Hi everyone,
    Im new to this forum so i dont know if this problem has been discussed before and is there any solution to it.
    I own a WRT54GC since January 2007 and have had no problems since then, but recently I found out some issues about the DHCP server on this unit:
    This is what i have on the network for you guys to understand my network setup:
    Cogeco Cable Modem for the internet (Im located in Canada), Linksys WRT54GC router, One Trendnet File/Print Server for my USB all in one Lexmark printer, and external hard drive, and an Acer laptop.
    The network works perfectly (wireless internet, wired internet, printing, file transfer) except for the following DHCP issue:
    DHCP server does not update the IP address of my laptop even if in the router settings i assign 5 mins or any minuites to the lease time of the IP address and I keep my laptop on and connected to the router either wireless or wired.
    The router has been enabled for DHCP and can assign the IP address automatically to my laptop upon powerup. I also have allocated 6 users for DHCP and starting IP at 192.168.1.101 which means that the range is from 192.168.1.101 to 192.168.1.106
    When I check who's connected to the network, I see that my lap is connected to it and the expiry of the lease time is given. I can also see that if the lease time is set to 5mins then it down counts until zero and it defaults to some wiered number after the time is over and doesnt change the IP address of my laptop. Looks like a bug in the DHCP server software. The above was tried when using the wireless connection.
    When I connected the laptop using the ethernet cable to the router (wired connection) a somewhat similar behaviour but instead if I set a lease time of 5mins or any other mins, the server does not recognize this and defaults it to a lease time of a day (similar to setting 0).
    I have configured my laptop for DHCP so I dont think there is anything wrong with my laptop but I do feel that the DHCP server on this WRT54GC is working abnormally.
    Any suggestions?......Try it out first and see if you have the same problem.
    If you dont than i will be glad if you could tell me how you were able to make it work!
    Cheers.
    (Edited post for guideline compliance. Thanks!)
    Message Edited by JOHNDOE_06 on 10-08-2007 11:26 AM

    Thanks for your reply. Im not looking forward to change my IP address every 5 mins. My question is more related the functional behaviour of the DHCP server. With all the proper settings (and I belive I have done the settings correctly), the DHCP server should update the IP addresses of any computer on the network after the lease period ends and provided the computer was on for the time the lease period is valid and not shut off. Even if I use the default lease setting of a day, it still does not change the IP address if I keep my laptop on for more than a day or so. I feel that the DHCP server is not functioning as it should. I dont really need to change my IP address and Im happy if it doesnt change, but I came across the abnormal behaviour when I was going through the setup. I just thought I should try to see how the DHCP server on this unit works and to see that it was not working as it should I thought I should ask someone on the community forum to see if this is really a normal behaviour or has linksys distributed a faulty product. My network works fine and Im the only user so Im not concerned about security. Im using WEP. To answer your other questions: There is no specific reason as to why I chose to limit DHCP to 6. I think 6 is good enough for me and as no one else is using my network I think 6 is an enough number for DHCP server to assign an unused IP address to my laptop after the lease period expires. I believe I dont need 50. The reason why I used 5 mins as lease time is because I wanted to test the DHCP server. 5 mins is short and I can wait and monitor to see if my IP address gets updated. Waiting for a day will be overkill for the simple test. Did you try it on your router? I'd be interested to know how it worked for you if it really worked. Thanks for you help!

  • How does the SetDefaultReport Method really work?

    I've looked in the forum and can't find the answer in enough detail for me to understand it.
    I need to create a new print button on a system form (delivery notes) and when the user presses it, I need to change the default report for the user/bp combination on the screen, invoke the print button, then return the user's records in the RDFL table back to what they were before I made a change.
    I have it working so that everything up to the changing things back is fine. (Although if the user doesn't have any defaults already, then I have to set the same default twice, because the first set assigns the system values, even though I assign a reportcode, layout code, card code and user id).
    But the main problem is if the user/bp combination did not have a default specified in RTYP before I made my change, then I can't get rid of my default record in that table, so the next time the user goes to print via the system print button, hoping to get the system default, my default report is going to print instead and that's not what they want.  Whew!
    Is there some place on the website that might explain this process in some detail?  For instance, why are their records in this table with a negative userid number & what does that mean?  Why does the user need to be a super user for me to do this via the DI but they can do it through the application without being a SU?
    I'd really appreciate any insights, and thank you.

    Hi Rasmus,
    In regards to your trouble getting the default report so that you can set it back when your done, I think I've gotten that figured out.  It appears to me that GetDefaultReport always returns the original default for a document that is used (from the RTYP table).  This is regardless of user/customer.  What I'm doing is looking in  RDFL by user & customer for any specific default and use it if found.
    If not found, then I use the getreportdefault & assign it to that user/customer.  This puts a record in RDFL which is not the way the system would do it (It would delete the record, I believe), but it seems to have the same effect.
                'get current default report for this user for delivery docs
                ReportCode = "DLN2"
                rs.DoQuery("Select dfltreport from rdfl where userid = " & USERID & _
                        " and doumntdode = '" & ReportCode & "' and cardcode = '" & cardcode & "'")
                If Not rs.EoF Then
                    HoldLayout = rs.Fields.Item(0).Value
                    'otherwise use the system default
                Else
                    'get report layout service
                    oReportLayoutService = oCmpSrv.GetBusinessService(ServiceTypes.ReportLayoutsService)
                    'get report params
                    oReportParams = oReportLayoutService.GetDataInterface(ReportLayoutsServiceDataInterfaces.rlsdiReportParams)
                    'Load the key for the default report
                    oReportParams.ReportCode = ReportCode
                    oReportParams.UserID = USERID 'This doesn''t seem to work. Changing user doesn''t change results
                    'get the default layout of the specific document (delivery note)
                    oReportParaDefault = oReportLayoutService.GetDefaultReport(oReportParams)
                    HoldLayout = oReportParaDefault.LayoutCode
                End If

  • Does the Report Generation Toolkit need Office?

    Quick question: Does the Report Generation Toolkit (V1.1.3 for LV 8.6) need Microsoft Office installed in order to create Word documents?
    I have a need to create reports, preferably in Word format, but the target machine may only have the Word reader installed, not Office.
    Thoric (CLA, CLED, CTD and LabVIEW Champion)
    Solved!
    Go to Solution.

    Yes, you need office.
    Regards,
    André
    Using whatever version of LV the customer requires. (LV5.1-LV2012) (www.carya.nl)

  • Does the ipod touch itself need wifi in order to use find my iphone??

    My ipod touch 4g got stolen and i have find my iphone turned on but my question is does the ipod itself need wifi to track it down??  I've tried so many times i played sound, i have a passcode lock on it, i even sent a message to my ipod... But i try to locate it, it says it's offline.it down?? if so there's no way to point to try to find it Right??

    Change your iTunes (Apple ID) password along with any other password that was stored in the iPod.  If any passwords are associated with credit cards, contact the CC company and get your card replaced (with a new number).  If any passwords are associated with a bank or any other savings institution, contact them also and discuss approprate action with them.
    The "Find my..." function is pretty much useless if the device is in the hands of a thief.  All that is necessary is for the thief to connect to any computer with iTunes and "Restore as new."
    The only real protection you have is with the personal information on the device rather than the physical device itself.  This requires action before the device is lost/stolen.  If the device has significant personal information, it should have a strong 8-digit (or longer) password AND be configured for automatic wipe in the event of ten consecutive incorrect password entries.

  • I have an iPod Nano 7th generation, and I keep getting an error saying that iTunes could not recognize my device. I have tried nearly everything,except I don't have admin rights on the computer, and really need help.

    I've tried a lot to get it to work, even using a new charger and putting it into Disk Mode. I really need help. Can anyone give me some advice? Thanks.

    Hi Dawson777,
    Thanks for visiting Apple Support Communities.
    It sounds like you're receiving the message "An iPod has been detected, but it could not be identified properly" when you connect your iPod nano to your PC. You have tried some good troubleshooting steps already, and you may want to review the additional steps in this article:
    iPod nano: Error message saying that iPod 'could not be identified properly'
    http://support.apple.com/kb/ts3218
    Best Regards,
    Jeremy

  • How does the BUILD menu work?

    I have a game project created and I am trying to get it built so I don't need a collection of 15 different folders and files to get it to work. So, How do I use the Build function to get the project onto
    ONE executable file?

    Hello Edavis85,
    What's your project in detail? When msbuild build projects, it is use project files such as csproj and vcproj. We use it to build our application. I'm not sure your scenario.
    Best regards,

  • Is the Entire J2EE Really Needed

    Hello there,
    I plan to develop, package, and deploy some servlets (and maybe some JSPs) just for experimental purposes.
    I have already downloaded the ENTIRE J2SE. I don't think I am prepared to wait another eon for the J2EE download to complete. Do I REALLY need to download the entire J2EE or just some of its tools to develop a working servlet? If "No", Can someone please tell me the important J2EE API/Tools/Class-files required to develop servlets that can run like any normal servlet out there with my already installed J2SE?

    Hello there,
    I plan to develop, package, and deploy some servlets
    (and maybe some JSPs) just for experimental purposes.
    I have already downloaded the ENTIRE J2SE. I don't
    think I am prepared to wait another eon for the J2EE
    download to complete. Do I REALLY need to download the
    entire J2EE or just some of its tools to develop a
    working servlet? If "No", Can someone please tell me
    the important J2EE API/Tools/Class-files required to
    develop servlets that can run like any normal servlet
    out there with my already installed J2SE?For just servlet development it is too much of overhead to do it on J2EEE. You can download tomcat which is also free and that will suffice.
    Regards,
    Ashoke Bhowmick

  • Does SJSAS PE 9 really need 512MB of RAM to run?

    Hello,
    According to the link below, the server needs at least 512MB of RAM. I did not deploy any application other than the samples so I am not sure if 512MB is really needed.
    http://docs.sun.com/app/docs/doc/819-3653/6n5s0v1qa?a=view

    Check this thread:
    http://forum.java.sun.com/thread.jspa?forumID=136&threadID=718605

  • Does the ipod universal dock need power?

    I have an ipod universal dock which I'm trying to connect to a video projector using s-video. Do I need to supply power to the universal dock in order to view videos from my 30GB ipod? onto my projection screen.

    Hi,
    I do not have the universal dock, so I am not 100% sure, if from what I read from the following link
    http://docs.info.apple.com/article.html?artnum=300251#tv
    It seems that you do not need the power supply to the universal dock, however, if you want to use the remote control of the dock, then you need to connect it either via a computer or iPod ac charger

Maybe you are looking for