Clean the Code example for the abstract factory

Hello
I read clean Code and I do not understand something.
On page 38, it is suggested to instead use the switch instructions, we can use the abstract factory.
The example is the following:
Instead:
public Money calculatePay(Employee e)
throws InvalidEmployeeType {
  switch (e.type) {
  case COMMISSIONED:
    return calculateCommissionedPay(e);
  case HOURLY:
    return calculateHourlyPay(e);
  case SALARIED:
    return calculateSalariedPay(e);
  default:
    throw new InvalidEmployeeType(e.type);
  }
}
We can do this:
public abstract class Employee {
  public abstract boolean isPayday();
  public abstract Money calculatePay();
  public abstract void deliverPay(Money pay);
}
-----------------
public interface EmployeeFactory {
  public Employee makeEmployee(EmployeeRecord r) throws InvalidEmployeeType;
}
-----------------
public class EmployeeFactoryImpl implements EmployeeFactory {
  public Employee makeEmployee(EmployeeRecord r) throws InvalidEmployeeType {
    switch (r.type) {
     case COMMISSIONED:
        return new CommissionedEmployee(r) ;
     case HOURLY:
        return new HourlyEmployee(r);
     case SALARIED:
        return new SalariedEmploye(r);
     default:
        throw new InvalidEmployeeType(r.type);
     }
  }
}
I don't see why the plant is necessary here. (I know not much make abstract and I am a beginner)
The abstract class used with his methods wouldn't be enough? Subclasses (CommissionedEmployee, HourlyEmployee,...) are implemented methods that can be called when necessary. Instead of calculatePay (myEmployee), we call myEmployee.calculatePay (). Doesn't it all? So I don't know why the plant is located in this example.

Thanks in advance for any help on this!

lemonboston

lemonboston wrote:
Subclasses (CommissionedEmployee, HourlyEmployee,...) are implemented methods that can be called when necessary. Instead of calculatePay (myEmployee), we call myEmployee.calculatePay (). Doesn't it all?

Well, Yes, that's all. Almost everything is. You're right, you call

myEmployee.calculatePay()

where "myEmployee" is an object of the appropriate subclass. But whence this object? At some point, you must have had a line that says

Employee myEmployee = new SalariedEmployee()

or something along that line. But how did you know to create a SalariedEmployee object and not a HourlyEmployee object? It must have been a few if statements going on there. And here comes the factory: you pass a token representing the employee at the factory (a type code of employee of a character, an employee number that it will search in a database, or something else) and the factory returns a derived object of this token.

Tags: Java

Similar Questions

  • Code example for single asynchronous reading of multiple waveforms

    Hello

    I looked around but have not been able to find the code example for single asynchronous reading of multiple waveforms.  Could someone point me in the right direction?

    Thank you

    Dale

    Hi Dale,

    Have you looked at the code using .NET Framework DAQmx example? It shows this code:

    class DAQmxAsyncRead
    {
    private AnalogSingleChannelReader reader = null;

    public DAQmxAsyncRead (task t)
    {
    Create the drive
    Reader = new AnalogSingleChannelReader (t.Stream);
    Acquire 100 samples
    Handful of IAsyncResult = reader. BeginReadMultiSample (100, New AsyncCallback (OnDataReady), null);
    }

    Public Sub OnDataReady (IAsyncResult i)
    {
    Recover data that has been read.
    At this point, all that occurred during the asynchronous read exceptions are thrown
    Double data = reader. EndReadMultiSample (i);

    You can call the method BeginReadMultiSample here once again
    }
    }

    In addition, this article: http://digital.ni.com/public.nsf/allkb/485201B647950BF886257537006CEB89?OpenDocument talk about different causes of the reserved resource error.

    Kind regards

    Alexandra Valiton

  • Code example for the information of the applicant

    Hello

    I need to get information from the applicant in Composite SOA. Can someone show me sample code to get information from the applicant in IOM 11 GR 2.

    Thank you

    Retrieve the Login of the applicant
    Object requesterXMLElem = getVariableData ("variableentree", "payload", "/ ns3:process / ns4:RequesterDetails / ns4:Login");
    String requesterLogin = ((oracle.xml.parser.v2.XMLElement) requesterXMLElem) .getText ();

    -Kevin

  • Need code examples for the use of the PL/SQL and popup areas

    Hi all

    I looked at the documentation, but it does not explain how to use it.
    I need to create a region using PL/SQL to retrieve data from the tables and print it on a plain HTML page/region I use APEX 4.0.2 and DB Oracle 11i

    Thank you!

    Hello

    You can do like this:

    DECLARE
    NUMBER OF V_SAL;
    BEGIN

    SELECT NVL (SUM (salary), 0)
    To emp_sal WHERE the emp_id =: P170_emp_id
    IN V_SAL;

    HTP.p (')





    Salary
    '|| LTRIM (TO_CHAR (NVL(V_SAL,0), 'FML999G999G999G999G990D00')) | »
    ');
    END;

  • myRIO C code examples

    Hi all

    I'm just starting to watch myRIO for use for programming in C labs

    with the students.

    Depending on the resources, there is a link to the C code examples, for example. on

    http://www.NI.com/Tutorial/14619/en/

    but this link is broken. Examples are still available?

    Thank you

    Select this option.

    Hi Mark,

    This is the link you're talking to the step 3 download NOR myRIO C examples and Documentation? I tried it myself and it worked fine.

    If it is this link, you are talking about try this: http://www.ni.com/download/labview-myrio-toolkit-2014/4949/en/

    I hope it works for you,

  • IS THERE A LIST OF THE DRIVERS THAT MATCH A FAILURE CODE? FOR EXAMPLE (0XDEEDFADE)

    IS THERE A LIST OF THE DRIVERS THAT MATCH A FAILURE CODE?  FOR EXAMPLE (0XDEEDFADE).  «I GET THIS WHEN I TRY TO CONNECT A RECORDER APPLICATION MY PC (WITH CODE SCREEN BLUE DEATH "DRIVER IRQL-NOT-DONOR-BASED EQUALITY).»

    [Moved from comments]

    There is no error like code: 0XDEEDFADE

    Usually due to a bad driver, or a faulty or incompatible hardware or software. Use the general troubleshooting of STOP the Messages above checklist. Technically, this error condition means that a kernel-mode process or driver tried to access a memory location to which it did not have permission, or at a kernel interrupt request level (IRQL) that was too high. (A kernel-mode process can access only other processes that have an IRQL lower or equal to, its own.)

    Make sure you uninstall and reinstall the drivers using the following general method.

    First of all, download the latest driver. Then perform the following steps.

    Click on Start Menu

    Right click on my computer/my computer

    Click on manage the

    Click Device Manager in the list on the left

    Find the device you are trying to uninstall by expanding the game appropriate device (network adapter/IDE ATA / ATAPI controllers)

    Right click on the device

    Click on uninstall (do not click OK in the dialog box that opens after hitting uninstall it)

    Put a check mark to remove software driver for this device (if this option is available, if not, just hit OK) and click OK

    Restart your computer only if Windows asks you to.

    Install the latest driver for the device.

    You can also:

    Sign in as an administrative user.

    First of all, download the latest driver. Then perform the following steps.

    Click on Start Menu

    Click on Control Panel

    Click on hardware and sound

    Click device (the last link under devices and printers) Manager

    Find the device you are trying to uninstall by expanding the game appropriate device (network adapter/IDE ATA / ATAPI controllers)

    Right click on the device

    Click on uninstall (do not click OK in the dialog box that opens after hitting uninstall it)

    Put a check mark to remove software driver for this device (if this option is available, if not, just hit OK) and click OK

    Restart your computer only if Windows asks you to.

    Install the latest driver for the device.

    My system specs

    System manufacturer/model number HP Pavilion e9110t

    Windows 7 Home Premium 64 Bit operating system

    Processor Intel (r) Core (TM) 2 CPU Quad Q9550 @ 2.83 GHz

    Card mother Pegatron IPIEL-A3

    6,00 GB Hundai HMT125U6BFR8C-H9 memory

    Graphics card ATI Radeon HD 4850

    Its Realtek High Definition Audio card / ATI High Definition Audio

    Monitor (s) displays Acer AL2216W

    Screen resolution 1680 x 1050

    Keyboard HP keyboard

    Mouse HP mouse

    Unknown/installed by HP POWER supply

    Generic HP case

    Cooling Stock Intel cooling

    Hitachi HDP725050GLA360 ATA Device 500 GB hard drives

    Internet download speed: 19.15 Mbps Upload: 1.67 Mbps

    Another news network adapter D Realtek RTL8168D/8111 Family PCI - E Gigabit Ethernet NIC (NDIS 6.20) network adapter 802.11n Wireless PCI Express Card LAN Adapter

  • try to clean the edges (photo for example in the thread)

    I hope that you guys can see, but there are small areas of unwanted brown color between each block of baby... What would be the best way to clean the brownish areas? Given that the image has a transparent background, I thought I could use a brush and color areas transparent Brown but I don't know how to do this. Can someone explain how the Brown areas with a transparent color brush? Or is there a better way... make me know... Thank you guys.

    Untitled-1.gif

    Is to add a layer mask white behind the layer and paint on the layer

    mask with a size of 1 px or pencil brush.

    Set the color of foreground on black and white background color (press the letter

    D on the keyboard).

    Paint with black to hide (delete) and white if you want to cancel one of the erasure.

    MTSTUNER

  • I bought a used laptop. How can I clean the computer and only the program that the value of the factory. It's a dv4000 HP clubhouse with windows xp

    I bought a used laptop and the previous ovner couldn't remember his password since it's been more than a year she opened a session.  How can I clean the computer and restore it to that only programs that comes with it when buying or facotry settings.  It's a HP Pavilion dv4000 with windows xp?  I have not all discs.

    Go here: http://h10025.www1.hp.com/ewfrf/wc/document?docname=c00006110&tmp_task=useCategory&cc=us&dlc=en&lang=en&lc=en&product=464513 and click on the link that best matches your computer (e.g., Presario, Pavilion and HP Compaq Business PC manufactured and sold in 2006 or later).

    Assuming that your computer is 2006 or later, following the links eventually will lead you to the following directions:


    Reformatting a hard drive should be considered a last resort to solve a problem with a computer system. The hard drive can be reformatted and reinstalled the operating system, using the system PC Suite hard disk recovery. Reformatting the hard drive will overwrite all data on the disk. To preserve the data, back up the data of the user as; letters, leaves of calculation, graphics and emails to an external storage device before you reformat the disk. If the PC does not work in the Windows operating system, see reformatting since the recovery disks .
    Do the following to reformat the hard drive and reinstall the operating system.
    1. Connect the PC to the power adapter.
    2. Close all programs.
    3. Click Start , click principally made programs , select System Restore and click on the PC recovery .
    4. When the recovery options are offered, select the option to perform the Recovery of PC and click Next .
    5. The PC will restart.
    6. When the recovery of the PC of welcome message, click OK to continue.
    7. In the system recovery Panel, select System Recovery . By default, the system will perform a complete reformat and will destroy all user data.
    8. Restart the PC when prompted.
    As alternative method for the steps above, click Advanced Options , select the destructive recovery option and click Next to begin the reformatting process.
    The PC is in original factory State and all data in the system, such as the place and the date must be reconfigured.

    NOTE: any software "trial offer" has been included in the original factory image, it will be reinstalled, but it won't work (the test period will have expired).  If so any trial software is a security antivirus software or others, before connect you to the Internet, you must uninstall (using an uninstall tool provided by the manufacturer if available antivirus software) and then install your own anti-virus software.  So, you should download the uninstallers necessary and installers (or buy the software on CD) using another machine before starting this project.

    NOTE 2: See the following important tips from MS - MVP PA supporter (once the restore is complete, click Start > run > winver > OK to determine what Service Pack you have):

    HOW TO get WinXP SP1 or SP2 fully patched after a 'clean install': http://groups.Google.com/group/Microsoft.public.WindowsXP.General/MSG/a066ae41add7dd2b

    1. download & save the installer for WinXP SP3 on your desktop:
    http://www.Microsoft.com/downloads/details.aspx?FamilyId=5b33b5a8-5E7...

    [Yes, you can jump SP2 if you run WinXP SP1.]

    2. read & take into account:
    http://msmvps.com/blogs/harrywaldron/archive/2008/05/08/Windows-XP-SP...

    3 connected as long as administrator, if necessary, double-click the saved file to install WinXP SP3.  Follow the prompts. Be patient and restart twice when the installation ends.

    4. make the resolution method 2 here (believe me):
    http://support.Microsoft.com/kb/943144

    5. go to http://windowsupdate.microsoft.com . Install all required software, and then click CONTINUE. Select CUSTOM and scan | Install the critical updates of security offered. Still, follow all the instructions.

    [I do NOT recommend install IE7 through Windows Update.]

    6. make sure that automatic updates is enabled; FC.
    http://support.Microsoft.com/kb/306525

    Other references:

    Free unlimited installation and compatibility support is available for Windows XP, but only for the Service Pack 3 (SP3), until April 14-09. Chat and e-mail support is available only in the United States and the Canada.

    Go to http://support.microsoft.com/oas/default.aspx?gprid=1173 . Select "Windows".
    XP"and select"Windows XP Service Pack 3 "

    5 steps to help protect your new computer before going online
    [installation clean = new computer]
    http://www.Microsoft.com/protect/computer/advanced/XPPC.mspx

    Measures to help prevent spyware
    http://www.Microsoft.com/protect/computer/spyware/prevent.mspx

    How TO get Windows XP Gold fully patched: http://groups.Google.com/group/Microsoft.public.windowsupdate/MSG/3f5afa8ed33e121c

    1. download & save the WinXP SP2 installer on your desktop:
    http://www.Microsoft.com/downloads/details.aspx?FamilyID=049c9dbe-3b8...

    [Yes, you can jump SP1]

    1B. download & save the installer for WinXP SP3 on your desktop:
    http://www.Microsoft.com/downloads/details.aspx?FamilyId=5b33b5a8-5E7...

    2. read & take into account:
    http://msmvps.com/blogs/harrywaldron/archive/2008/05/08/Windows-XP-SP...

    3. administrator, if necessary, double-click the saved file to install Windows XP * SP2 *.  Follow the prompts. Be patient and restart twice when the installation ends.

    3B. logged on as administrator, if necessary, double-click the saved file to install WinXP SP3.  Follow the prompts. Be patient and restart twice when the installation ends.

    4. make the resolution method 2 here (believe me):
    http://support.Microsoft.com/kb/943144

    5. go to http://windowsupdate.microsoft.com . Install all required software, and then click CONTINUE. Select CUSTOM and scan | Install the critical updates of security offered.  Still, follow all the instructions.

    [I do NOT recommend install IE7 through Windows Update.]

    6. make sure that automatic updates is enabled; FC.
    http://support.Microsoft.com/kb/306525

    References with dubbing:

    Free unlimited installation and compatibility support is available for Windows XP, but only for the Service Pack 3 (SP3), until April 14-09. Chat and e-mail support is available only in the United States and the Canada.  Reach
    http://support.Microsoft.com/OAS/default.aspx?gprid=1173 | Select "Windows".
    XP"and select"Windows XP Service Pack 3 "

    Protect your PC!
    http://www.Microsoft.com/athome/security/computer/default.mspx

    Learn how to protect your PC by taking the three simple steps
    http://www.Microsoft.com/downloads/details.aspx?FamilyId=3AD23728-497...

  • Is there a bar code scanner / code reader for iOS which displays the information in legible characters human bar?

    Is there a bar code scanner / code reader for iOS which displays the information in legible characters human bar?

    Hello. Have you looked in the app store? There are many people who can do this by using the camera in the phone or iPad. Some also work on images in the Photos.

  • find the code forgot for new iPhone 5SE

    What is the best way to find my code forgotten for my new iPhone 5Se.

    I put my iPhone in airplane mode and after a few hours of walking, my itouch asks after the code to unlock the iPhone again. Because I don't remember my code, is there any other possibility to open

    If you have forgotten the password. Unfortunately, these are the only options available. Good luck.

    https://support.Apple.com/en-us/HT204306

  • What is the code name for intex fx cloud (required to manually build 2.0)

    I want to manually build the last B2G for an intex phone fx cloud. The build process requires executing the script "config.sh' with the name of the phone code:
    https://developer.Mozilla.org/en-us/Firefox_OS/Preparing_for_your_first_B2G_build#Configuring_the_B2G_build_for_a_mobile_device

    The phones operating system supported firefox page does not display the code name for new devices:
    https://developer.Mozilla.org/en-us/Firefox_OS/Developer_phone_guide/Phone_specs

    Is it possible to get the code for intex phone name. If the list of the devices supported by "config.sh" does not include the code name of intex, is there a way to still be able to build the latest os from firefox for the intex device?

    Hi Notalex,

    The code name for the Intex Cloud FX device is Tarako. However, it uses another optimized codebase that the regular B2G is based so that it can run on lower range with little memory devices.

    Unfortunately, version 2.0 of the B2G code base would go not on the Fx cloud Intex due to material limitations.

    For more information and advanced issues on customizing your Firefox OS device, you can visit the following pages:

    I hope you find this information useful. Please let us know if you have any questions of usability with your new Firefox OS device.

    Thank you!! =)

    -Ralph

  • ICloud Keychain how can I change the phone number needed to verify the code text for me? The number it was sent is an old phone number of my friends that I do not have access to the.

    ICloud Keychain how can I change the phone number needed to verify the code text for me? The number it was sent is an old phone number of my friends that I do not have access to the.

    Try this from another thread I saw.

    On iOS, go to settings > iCloud > keychain and tap button to disable iCloud keychain. (you will be asked to delete or keep the passwords on device) I chose to delete...

    Then turn it back on, and pop - up chose reset iCloud trousseau, on a chosen pop-up confirmation reset

    In the new window pop up use iPhone password like iCloud cryptogram? has chosen the use code

    Enter your secret code (4 digits) then choose country and your new phone number

    Although, to "Restore the iCloud Keychain," I took to erase the data and essentially set up a new keychain.  Not the case.  Strangely, after essentially bypassing the security system, setting a new password and verification number, I see my cards, passwords and other data have been restored.  Maybe it's all the iCloud account and this master password.  Or maybe it's a bug.  With Apple, we'll never know.

    Also have a look here: get help using iCloud Keychain - Apple Support

  • Pavilion a6230n: How can I get the product code (UPC) for an HP computer?

    Hello, I'm selling an old HP desktop that I hang out on Amazon.

    But in order for me to post on Amazon, I need to create a new list, since nobody else is for sale. To create a new list, I need a product code unique for the desktop computer. I'm looking for the Universal Product Code (UPC). A UPC code is the bar code that would be tested at the point of sale when someone buys something.

    I have a few other computers, I'm trying to sell, and on the site Web of Toshiba, the first manual I opened a laptop shows me the UPC. HP manuals don't.

    I tried to call customer service. And both times I'm hung up or disconnected. It's very frustrating because I have a very basic question, and does not have I gotten a response yet.

    If someone can find the UPC for HP Pavilion a6230n and tell me how to get the Cup for HP products in the future, I would be very happy. Thank you!

    Hello @RYoder15,

    There is not much else I can suggest.  I tried at length to see if I could find anything in what concerns this information without success.  Maybe if you are able to find the product packed in the store?  I was able to find the product on Amazon here: HP Pavilion a6230n desktop PC

    I hope this helps.

    Kind regards!

  • create the code lock for computer book note

    How to create the code lock for computer book notices

    Enter the BIOS, select the Security tab and set the power on password.

    I strongly recommend that you write the power on password and put somewhere safe. If you have forgotten the password turned on, you will find that you will need to send your laptop to be repaired by HP. This is not free of cost. Once a button inside the laptop password reset are over.

    I can't be more precise, as you have not identified your laptop with its full product name or product number.

  • Need information about the data included in the example for the inner race with flaws

    Hello

    There are several examples for fault detection in bearing (Vibration tool sets). I need more information about these data include:

    -Bringing its specifications

    -How to perform data acquisition

    -a link to the tutorial

    I came across this manual that shows how to use OATS envelope detection VI to perform detection of failures of bearings.

    http://zone.NI.com/reference/en-XX/help/372416A-01/svtconcepts/cst_speed_brg/

    It lists the specifications of turnover:

    • Inch diameter 0,2813

    • Primitive diameter: 1,1228 inch

    • Speed: 1 234 RPM

    It also goes to the list of characteristic frequencies determined by these attributes.

    The data acquisition is carried out by the use of an accelerometer and a tachometer. These devices measure the vibration and the rotation speed of the bearing data. Failure detection uses a method called detection of the envelope to look at the signals of the bearing and compared to signals of standard bearings to the discovery of flaws. You can learn more about the method of acquisition of data here:

    http://zone.NI.com/reference/en-XX/help/372416A-01/svtconcepts/fault_detection/#Envelope_Detection

    The first link is a tutorial on the detection of failures in the bearings. The end of the link provides the location of an example VI that may also be useful.

Maybe you are looking for

  • Satellite P20 - system sounds work but nothing else

    I have a P20-552 (PSP26E-025E9-S4) which is a little more than two years. This morning he suddenly decided to not play some sounds. System sounds play as usual as do all soundtracks from my video editing software (Adobe Premiere Elements). However, w

  • Problems with references to cRIO as startupApp

    I am having trouble with my programs that run as starting applications on of different cRIO. The problem is that it takes too long to load correctly references (or load at all). In the attached screenshot, there are two tabs that I put the State enab

  • Understand the global optimization VI

    Hello I have a task that requires the use of potimization overall, however, I'm not really familiar with it. I tried to look at the example of VI, however I have a hard time understaniding where my data would go. My current task includes measuring th

  • Service Pack 2 installation problem

    It's very strange. 1. the laptop is a Sony where install a Vista - 32-bit clean has been made some time ago, in Portuguese, because he's my friend of the Brazil. 2. the properties of the computer says that it has installed ServicePack 1. 3. the updat

  • Error number 0 x 802480015

    can not update windows xp error number 0 x 80248015 please help