Question about EffectiveJava 2nd edition 2, Model Builder

The generator class is to duplicate the properties of the class of Nutrition, it is not an "antimodel" as the copy - paste of code? Why not the class generator to create an instance of the NutritionFact and fill by modifying the properties directly or via private setter methods? Then in the method Builder.build () of the constructor is passed to the constructor of the NutritionFact. Wouldn't be easier to not create this cyclic dependency between the two? Wouldn't be the responsibility of the Builder to build the NutritionFacts, why NutritionFact don't know anything about the generator.

Here's the code for the book,

< pre >
package ej.itemtwo;

public class NutritionFacts {}

Private final int unsaturatedFat;
Private final int portions;
Private final int calories;
Private final int fat;

Public NotInheritable class Builder {}

Required parameters
Private final int unsaturatedFat;
Private final int portions;

Optional parameters - initialized with default values.
private int calories = 0;
private int fat = 0;

public Builder (int unsaturatedFat, int portions) {}
this.servingSize = unsaturatedFat;
This.Servings = portions;
}

public Builder calories (int val) {}
calories = val;
Back to this;
}

public Builder fat (int val) {}
bold = val;
Back to this;
}

public NutritionFacts build() {}
new return NutritionFacts (this);
}
}

Private NutritionFacts (Builder builder) {}
unsaturatedFat = builder.servingSize;
portions = builder.servings;
calories = builder.calories;
bold = builder.fat;
}
}

class customer {}

{} public void usage()
NF NutritionFacts = new NutritionFacts.Builder (1, 2) .fat (1) .calories (3)
. Build();
}
}
< / pre >


Published by: user12063116 on November 11, 2010 07:09

Published by: user12063116 on November 11, 2010 07:46

Published by: user12063116 on November 11, 2010 08:06

Published by: user12063116 on November 11, 2010 09:54

Published by: user12063116 on November 11, 2010 09:55

SaadKhawaja wrote:
The generator class is to duplicate the properties of the class of Nutrition, it is not an "antimodel" as the copy - paste of code?

Ah, something I finally qualified to answer. and one of my favorite new models of EJ2 :-).

The point of a generator, it's that it is used when the alternative is
(a) a manufacturer with a large number of parameters.
(b) a large number of permutations of different constructor that leave undefined by default values.

Why not the class generator to create an instance of the NutritionFact and fill by modifying the properties directly or via private setter methods?

Because it is a protection against the evils of the thread safety. Essentially is a proto-objet who "looks like to" the object to build, but you create the end object in a single call, completely formed (and very probably immutable). And for this reason, manufacturers should never have "getter" methods, and all its fields should be private. Maybe "delayed constructor" is a better term. I'm not sure.

Then in the method Builder.build () of the constructor is passed to the constructor of the NutritionFact. Wouldn't be easier to not create this cyclic dependency between the two?

No (see above).

It would not be the responsibility of the Builder to build the NutritionFacts...

This is exactly what it does, but not as long as you're good and ready and call build().

... Why does need NutritionFact to know all about the generator.

It is not (and probably shouldn't). The generator is a nested class because it relates specifically to the class she built. The needs of Builder for immersive sound class, but not vice versa; and for this reason, there is an argument for calling all Builder classes "Builder."

Winston

Published by: YoungWinston on November 12, 2010 12:13 AM

Tags: Java

Similar Questions

  • Question about DPS Professional Edition

    Hi all

    I am building an application with simple edition for my client using my CC, now, my client has decide that it wishes to target Android devices. Please correct me if I am wrong in that my client will pay now.

    Professional Edition monthly $495 x 12mos = $5940

    Question: Does my client gets the 250. Free Folio on a monthly or is - just a deal for the 1 year of time service?

    Nothing else that I'm missing or should consider? Thank you.

    Download of 250 each month is free for the first year only. In the second year, they need buy folio extra packs download.

  • X 6 ban-Questions about the 2nd HARD drive

    Hello

    I intend to buy the 2nd disc HARD adapter (http://www-307.ibm.com/pc/support/site.wss/document.do?lndocid=MIGR-61255)

    My questions:

    1.) do I need a special "cage" for 2.5 HARD disk? I remember it was necessary with older 2nd HDD adapters (as for my T40)...

    2.) I'll be able to start from there?

    (3.) I can use any disk SATA 2.5 here? I looked up the Western Digital Scorpio to be a good player?

    (4.) the speed of the interface must be 3 Gb/s or 1.5 Gbit/s?

    Thank you for your opinion on this...

    (2) Yes, you can when you set the boot order in your BIOS

    (3) you can use any disk SATA 2.5 9.5 mm thick, but the final interface of your adapter is Enhanced IDE

    (4) would not issue final connection of your caddy to the laptop is through E-IDE, which is well below the maximum 1.5 Gb/s of a SATA 1.5 mode.

  • Questions about the professional edition of DPS

    Hello

    I'm trying to find information on the professional edition of DPS but is unclear to me, maby someone could help me?

    Issues related to the:

    1. how musch does it cost and where on the Adobe site can I buy it? And how many downloads are included?

    2. is it necessary to have a CC account also? I have a subscription to CC for now, but only because I wanted to use unique DPS now retirement edition. But all my indesign work is done on a CS6 license I bought before the introduction of CC. So my question is, can I buy a professional edition of DPS and use it with CS6 without subscription of the CC?

    3. If I want to publish an app multifolio with 3 separate applications for sale inside ($ app a 3.99, app $ two 4.99, in-app three 8.99 dollars) and I want to sell this app the same multifolio on the Appstore, Google play and store Windows, can I do this with a SINGLE professional edition license?

    4. the app I want to publish as 2048 x 1536 and works well with my iPad to the retina. The resolution will also work with tablets of high resolution with android or windows on it?

    Hope someone out there chip can help out me

    Alex

    I don't have a handy link for the number one, but it's $400 / cooler months of download.

    2 n ° CS6 is still supported but I have no idea how long it will continue

    3. you are doing is not in a folio multi apps application, you have folios. As long as it's the same application, you can sell on Windows, the game of Google and iTunes app store.

    4. use folios PDF 1024 x 768 and your a folio will work perfectly on all devices except iPhone.

  • questions about dps professional edition

    Hi, I would like to make you a few questions.

    I develop a digital magazine for a client, and I have to carry a magazine of Pentecost one release every 3 months.
    So I would like to know if it's better for me is a professional monthly or annual edition.
    That means, for the monthly professional edition, 250 folio download a year? And many consider each magazine version or just one? (I want to say, 250 download for each new magazine version 4 per year)

    If I download the version number 251, what will happen?

    Another question, if I subscribe monthly edition, the version number 3, will disappear after the month I paid?

    Thank you and sorry for the bad English!
    Andrea

    For examples of simple editing, you can take a look at Adidas Outdoor, for professional, take a look at loop Magazine, Magazine etc. blades. The diferrence major that you will notice is that with editions Professional, Apps have the ability to post multiple questions in an application, so it didn't need to introduce the new application to Apple and get it approved, whenever you have a new version of the question, with simple editing on the other end, each issue would be built in app, and whenever there is a new question/version will be submitted to Apple for review. Also with Professional Edition, you have an option to publish on the kiosk, Amazon, Android, iPhone. While the only edition is currently only available for the iPad.

    Thus, according to your priorities, decide that for yourself.

  • 15 - an051dx: special speaker and backlit keyboard questions about Star War Edition

    Hi guys, I just bought Star War Special Edition laptop with B & O speakers. Is there anyway can I change that in order to get better sound quality on my laptop? In addition, the laptop comes with backlit keyboard, therefore is anyway can I adjust the timing for her? Thank you and have a nice day.

    Hi @StevenChau,

    Please use the following link to create yourself a file number, then call and it can help to expedite the appeal process:

    Step 1. Open the link: www.hp.com/contacthp/
    Step 2. Enter the product number or select Auto detection
    Step 3. Scroll up to "still need help? Fill out the form to select your contact options.
    Step 4. Scroll down and click on: contact HP options - click Get phone number

    File number and phone number are displayed.

    They will be happy to help you immediately.

    You can say thanks for trying to help by clicking on the Thumbs Up below!

    Thank you.

  • A question about the comparison with REGEXP_LIKE models and [[: alpha:]]

    Hi all

    I created the following table:
    CREATE TABLE names(
    name VARCHAR2(10));
    
    INSERT INTO names(name) VALUES('dariyoosh');
    INSERT INTO names(name) VALUES('John');
    INSERT INTO names(name) VALUES('Peter');
    INSERT INTO names(name) VALUES('Frank');
    INSERT INTO names(name) VALUES('Bernard250');
    INSERT INTO names(name) VALUES('Jack12');
    Now, I want to write a query that returns the names that consist only of letters. So I wrote:
    SELECT name
    FROM names
    WHERE REGEXP_LIKE(name, '[[:alpha:]]+');
    However, this also returns alphanumeric names. I don't understand why, because I know (please, correct me if I'm wrong)
    [[:alpha:]]
    refers only to letters, no?

    You kindly could guide me where I made a mistake in my query?

    Thanks in advance
    :)

    Hello

    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    
    SQL>
    SQL> SELECT NAME
      2    FROM names
      3   WHERE REGEXP_LIKE(NAME,
      4                     '^[[:alpha:]]+$');
    
    NAME
    ----------
    dariyoosh
    John
    Peter
    Frank
    
    SQL> 
    

    Kind regards

  • Question about HP ZR2440w monitor (new model)

    Hi, monitor 24 inch HP ZR2440w use Super IPS technology? His predecessor, ZR24w used this feature, but I'm not sure of ZR2440w. There was no mention of S - IPS on of the ZR2440w specifications.

    Thanks in advance.

    From what I see, it uses the e - IPS and not S - IPS technology. You can see the difference between the two here http://www.tftcentral.co.uk/articles/content/panel_technologies_content.htm#e-ips

  • HTML (Web), I have a question about the models.

    Hello CC animate developers.

    New features are really good.

    HTML (Web), I have a question about the models.

    <! DOCTYPE html >

    < html >

    < head >

    < meta charset = "UTF-8" >

    < title > $TITLE < /title >

    < meta name = "ad.size" content ="width = $WT, height = $HT" > "

    $CREATEJS_SCRIPTS

    $SCRIPT_START

    var canvas, stage, exportRoot;

    function init() {}

    $CJS_INIT

    }

    $PLAYSOUND

    $SCRIPT_END

    < script type = "text/javascript" >

    "clickTAG" var = "";

    < /script >

    < / head >

    < onload = "init (); the body"style =" background-color: #D4D4D4; " margin: 0px; ">

    < a href = "javascript:window.open (window.clickTag)" >

    < div style = "position: absolute;" cursor: pointer; box-sizing: border-box; border: 1px solid #000000; overflow: hidden; height: $HTpx; Width: $WTpx; Background: rgb (255, 255, 255.0); "> < / div >

    < canvas id = "$CANVAS_ID" width = "$WT" height = "$HT" style = "background-color: $BG" > < / canvas >

    < /a >

    < / body >

    < / html >

    In the example above, the model;

    < Meta name = "ad.siz of" content = "width = $ WTI height = $ HT" > "

    and

    < Div style = "position: absolute;" cursor: pointer; box-sizing: border-box; border: 1px solid # 000000; overflow: hidden; height: $HTpx; Width: $WTpx; Background: rgb (255, 255, 255.0); "> < / div >"

    I use labels. But these tags in the template and import, it gives an error does not occur.

    I think it was a mistake. I want to help in this regard.

    $ HT or Properties $WT , I get an error when I use elsewhere.

    I think I should be able to use anywhere I want.

    The same problem here - I worked around by some DRM models with different values of ad.size, but it's a solution quite short-seight

    Also - you are not able to create the model with transparent background by removing style = "" background-color: $BG ' as it also throws errors - is the only solution that I managed to get updates style = "background-color: $BG; background: none; ", but it's a really bad way of coding things.

    It would be really great to have freedom in changing patterns.

  • A question about the license of Oracle 1 g R2 Enterprise Edition

    Hi all


    I have a question about Oracle license and I would be grateful if you could help me thanks.

    I installed an Oracle (11g R2 Enterprise edition) server on a virtual linux machine. The pc being used for this purpose
    is my cell phone company (so a professional and not a personal computer). However, I use this Oracle Server
    only for the purpose, i.e. learning only to run the examples in my Oracle Press books (SQL, PL/SQL and some)
    administrative tasks) just to learn things.

    There is absolutely no data related to my business, stored or used on this server. Whenever I want to work with my
    data of the company, I use the Oracle server of the company that has the appropriate license of course. So, as I said, I
    Use this server of the company on the virtual machine only to run applications/programs in my Oracle Press books just for
    learning and I'm the only person who uses this server (no remote for other users).

    The reason why I needed to install this server on my PC, is that our DBA could not provide a training environment
    for me, with all the privileges and features.


    Should I buy a license for this Enterprise Server installed on my virtual machine?


    Thanks in advance,
    Dariyoosh

    The OTN license agreement:

    >
    LICENSE RIGHTS
    We grant an exclusive, non-transferable, limited license to use the programs only for the purpose of developing, testing, prototyping and demonstrating your application and not for other purposes. If you use the application you develop in this licence for any internal or for any commercial or purposes data processing production, or you want to use the programs for purposes other that those permitted under this agreement, you must get a production version of the program by contacting us or a reseller of Oracle to obtain the appropriate license. You acknowledge that we may not produce a production version of the programme and the development efforts undertaken by you at your own risk. We can check your use of the programs. Program documentation, if any, may be consulted online at http://otn.oracle.com/docs.

    Ownership and Restrictions all retain us the property and rights of intellectual property in the programs. Programs can be installed on a single computer only and worn by one person in the operating environment identified by us. You can make a copy of the program for backup purposes.

    You can not:
    -Use programs for your own internal data processing or for commercial or production purposes, or programs for any purpose except the development of your application.
    -use the applications you develop with programs for any internal data processing or commercial or production without obtaining an adequate license from us;
    -continue to develop your application after using for any treatment data internal, commercial or production end without obtaining an adequate license from us, or Oracle reseller;
    -remove or change any brand of program or a statement of property rights;
    -put the programs available in any manner to a third party;
    -Use programs to provide a third of training;
    -assign this contract or give or transfer the programs or interest to them to another person or entity; -cause or permit engineering reverse (unless required by law for interoperability), disassembly or decompilation of the programs;
    -disclose the results of benchmark tests of any program without our prior written consent.

  • A few questions about the difference between the Satellite P70, L70, S70

    Hello, I have a lot of questions about the P70, L70, S70 series that come with a 1920 x 1080 panel.

    (1) what are the differences between the L70 and S70 series? With the exception of the RAM and HARD drive capacity, books seem pretty identical.

    (2) P70, L70, S70 doesn't support a 2nd HARD drive or it's just the P70 series that support?

    (3) all the three (P70, L70, S70 series) come with the same TFT panels?

    (4) of the above series, which supports mSata?

    (5) all the model of each series are delivered with support from mSata? For example, it could be that L70 - a - 13 m supports mSata is not the case of the L70-a-146?

    (6) all the foregoing, are delivered with a S - ATA II or III S - ATA interface?

    (7) who is the best of these series listed? I'm trying to understand what makes the big difference of S70 to P70 except for the envelope for example.

    Thank you in advance.

    > (1) what are the differences between the series L70 and S70? With the exception of the RAM and HARD drive capacity, books seem pretty identical.

    What models Sat L70 and S70 do you mean exactly? There are different L70-xxx-xxx and S70 models on the market that supports different hardware specifications.

    (> S70 2) P70, L70, support a 2nd drive HARD or is - it just the series P70 that support?
    As you can see in this [Sam P70 HDD replacement document, | http://aps2.toshiba-tro.de/kb0/CRU3903II0000R01.htm] the P70 series supports the 2nd drive Bay HARD, BUT even if there is a 2nd HARD drive Bay, this does not mean that you can use the 2nd HARD drive. In the case where the 2nd HARD drive Bay are equipped with HARD drive connector, you can use the 2nd HARD drive

    I also found the [Sam L70/S70 HDD replacement | http://aps2.toshiba-tro.de/kb0/CRU3703HG0000R01.htm] the document on the Toshiba page and there I see this 2nd HARD drive Bay is not available

    (> 3) all three (P70, L70, S70 series) come with the same TFT panels?
    See point 1). Different P70, L70, S70 models were equipped with different material parts.

    (> 4) of the series above, which takes in charge mSata?
    As far as I know that some P70 models are equipped with an mSATA SSD of 256 GB.

    (> 5) do all the model of each series are delivered with support mSata? For example, it could be that L70 - a - 13 m supports mSata is not the case of the L70-a-146?
    See point 4) not all models supports the same hardware specifications

    (> 6) all of the above, come with a S - ATA II or III S - ATA interface?
    I don t think that SATA III is supported. I guess it would be SATA II

    (> 7) which is the best of these series listed? I'm trying to understand what makes the big difference of S70 to P70 except for the envelope for example.
    Not easy to answer because there are too many models released in Europea.
    And not all models are available in each country. So I guess you will have to look for the models that have been released in your country.

  • Question about the new Yoga 10 HD +.

    Hello

    A few questions about the new Yoga 10 HD + that I hope you can answer.

    I bought the former model, last year. Love the design and long battery life, but a few major questions made me return.

    • Somewhere that I've read that it can not read NTFS on USB so I guess that's the same thing with a NTFS formatted microSD card?
    • Can it read exFAT formatted microSD cards?
    • Anyone who has questions about the audio via bluetooth?
      (I know that BT is not exactly High End HiFi but the old 10 Yoga for some obscure reason - most likely a driver problem which nobody cared to fix - rang * very * worst with visibly distortion while both my phone and a Tablet noname cheap I have zero about fidelity - any of my devices bluetooth audio) I tried aptX or not)

    So to avoid buying it back it also I really I would like to see if I can get my questions answered before buy you.

    While I love the form factor and long term issues above are only two Mayor dealbreakers for me. Bad audio quality = no joy listen to spotify, local etc. MP3s. not of NTFS or exFAT = some great movies.

    My old noname android Tablet really could use an upgrade so I'm really curious it may be, or I should watch the competition and will be form factor and battery LIFE.

    Thanks in advance.

    EDIT:

    If it does not support NTFS or exFAT on microSD card have someone at - he tried ext3 or ext4?

    I mean with Linux Android root, it should be a no-brainer to support at least when it comes to royalties unlike NTFS or exFAT where it * might * have some trouble with Microsoft.

    I used a USB through a USB OTG cable. NTFS or exFAT have been recognized by the Tablet PC. FAT32 is seems to be the preference.

  • Question about the possible use of MSVC 2008 Express as an external compiler CVI 9.0

    I was looking for these messages looking for information on the use of the ICB with external compilers, especially from MSVC 2008, and I came across this ad are about 4 months:

    "CVI 9.0 and MSVC 2008 express.

    The title of this announcement means that the freely downloadable 'express' version of MSVC can be used with CVI 9.0, but the body of the message is not in the details.  But I would really like to know if this is possible, and I'm guessing there are others here who could be very interested as well.  Page 8 of the CVI 9.0 release notes does not indicate that the Express version is supported, which makes sense.  I say this because I always thought that "express" versions of the MSVC were only to create .NET applications (C + c++ / CLI) and applications not native to Windows.  Or does change with the release of MSVC 2008 Express?

    There is no hurry to answer...

    JB

    If you have a CVI 9.0 FDS(I'm not sure about the BDS)

    Select Options/Build Options

    Select the Select button to the right of 'compiler active'.

    Click 'new' to create a new configuration of external compiler

    Select MSVC 9.0 as a model.

    Choose a configuration name (what you choose to CVI) and a destination file (where the external compiler settings will be stored).

    Click OK

    After that, you can easily select the optimizing level and the level of warnings that you need through the "Edit" in the box "compile to realease configuration.

    Kind regards

    Nicolas

  • Question about Dell OEM: SLP Windows 7 Installation disk domestic; can it be installed and activated on other computers from Dell?

    I bought a Dell installation disk and I want to use it to install a better version of Windows on my Dell PC. I have windows Vista and I want to use it to update my OS Windows7 Home Premium. However, the license type is SLP:OEM and no detail... not sure what SLP: OEM means... I thought that the OS discs are the same. Someone told me no retail editions are not suitable for a new OS, but I'm confused. The disc says, Windows 7 Home premium 64-bit, but didn't holograms who have all MS OS disks and the disk is labeled for use with a Dell system only, if the means it will work very well on my Dell PC? The label does not which brand or model this disc is for, but said only for the Dell PC which is my PC. I'm assuming, the disk won't work on all Dells, maybe someone can offer suggestions, any help is much appreciated. Thank you!

    I have a few other questions about Windows 7, can I ask you about this on your Web site? Do not know how to contact you on your website. I can see other people responding to your articles, but that's all. I thought that maybe their might be a forum to post a question... Thank you for everything.

    You can comment on my site but comments will be public and it is easier to answer questions in the forums.

    If you want to be more precise, you can post in the Dell Community Forums. :

    http://en.community.Dell.com/support-forums/software-OS/

    There are also ways to private message me there is something I don't think that can be done by non-moderateurs on Microsoft Answers. However, I prefer answering questions on the forum:

    http://en.community.Dell.com/members/natakuc4

    Concerning the compatibility with Windows 7, I have listed a full pilot system here compliment:

    http://dellwindowsreinstallationguide.com/driver-sets/Inspiron-desktops/Inspiron-518-Windows-7-64-bit/

    Theres nothing to worry about your circuit board, the only driver who can break your system's BIOS update. I only list the last official update BIOS list Dell in my unofficial driver sets.

    The webcam should be covered by Dell Webcam Central but what is the monitor?

    http://ftp.Dell.com/Monitors/Dell_SX2210-Monitor_Webcam%20SW%20RC1.1_%20R230103.exe

    The main difficulty is to get a genuine product key Windows 7 64 bit. The time now it's easier to buy the 64-bit Windows 8.1. No matter if you buy Windows 7 or 8.1 64-bit both going to Windows 10 free when the RTM is out.

  • Question about the RV130W compared to RV110 &amp; RV215W

    Hey,.

    I decided between the following routers; the RV130W ($220 ~), RV215W ($140 ~), & RV110W ($110 ~)

    Then my agent support call referred to as Gigabit RV130W, being the best and fastest according to him. He also told me that the RV110W of RV215W & are Fast Ethernet. My questions are, what is the difference between Gigabit and Fast Ethernet? Is it worth paying the extra $80 - $ 110! ~ to the RV130W and why.

    Edit: My office building has a few different rooms with between the two walls, we to a maximum of 10 people connected at once and as far, it should go is about 50 ft.

    Thank you

    Matthew

    Hello

    Concert speed is 1000 Mbps (megabits per second) and Fast Ethernet 100 Mbps.

    Thus, the concert is 10 times faster.  Yes, the fastest speed is recommended for performance.

    The RV130W will give you the best performance at all levels.

    -Better throughput on the Internet

    -Best speed in the network internal

    -Stronger antenna with a dBi gain 2 verses 1.8 on the 110 and the 215W

    -Several advanced features with more options VPN

    Here is the link to the technical data sheets:

    RV110W:

    http://www.Cisco.com/c/en/us/products/collateral/routers/RV110W-wireless...

    RV215W:

    http://www.Cisco.com/c/en/us/products/collateral/routers/rv215w-wireless...

    RV130W:

    http://www.Cisco.com/c/en/us/products/collateral/routers/small-business-...

    Best regards

    Mike

Maybe you are looking for