How to enforce factory instantiation?

Lets say I want all subclasses of a certain class to be created through a factory. I want to disallow instantiation of subclasses through direct instantiation using "new" .
How can I enforce that? I would like the baseclass to enforce this, so that it should not be possible to define subclasses with a public constructor. If the baseclass has a protected constructor, it seems that subclasses still can have a public one?

One solution to your problem is to only declare an interface for the types that the factory will create and put the implementation classes as inner classes in the factory. That way, noone will ever be able to construct the instance of them except the factory:
public class Factory
    private Factory(){...}
    class ProductImpl_1 implements Product
    class ProductImpl_2 implements Product
    public Product getProduct(String type)
       // return the correct implementation based on the type
public interface Product
}

Similar Messages

  • How to Restore Factory Settings on a Mac?

    How to Restore Factory Settings on a Mac OS X 10.6.8?
    I have been told you can do this without the Installation CD. I also do not remember the installation CD when i got the laptop. If it's possible then please someone let me know! if not then how can i get a new CD to do this?
    my computer keeps freezing on me at random times, and i have tried taking the laptop to my college tech support and also Best Buy and they said they can't do anything and that i need to try resetting the mac.

    You may not remember the installer disks but they came in the box. Your profile shows you are running 10.6.6 Snow Leopard. To restore back to factory settings you need those disks. That said to go that route may be unnecessry. Stay away from Best Buy tech people. They know nothing. Without the disks you do a repair disk to see if that helps:
    Start up your computer in single-user mode to reach the command line.
    Note: If necessary, perform a forced restart as described in the Emergency Troubleshooting Handbook that came with your computer. On desktop computers, you can do this by pressing the reset/interrupt button (if there is one) or holding down the power button for several seconds. On portable computers, simultaneously press the Command-Control-power keys. If your portable computer doesn't restart with this method, you may need to reset the Power Manager.
    At the command-line prompt type:
    /sbin/fsck -fy
    Press Return. fsck will go through five "phases" and then return information about your disk's use and fragmentation. Once it finishes, it'll display this message if no issue is found:
    ** The volume (name_of_volume) appears to be OKIf fsck found issues and has altered, repaired, or fixed anything, it will display this message:
    ***** FILE SYSTEM WAS MODIFIED *****
    Important: If this message appears, repeat the fsck command you typed in step 2 until fsck tells you that your volume appears to be OK (first-pass repairs may uncover additional issues, so this is a normal thing to do).
    When fsck reports that your volume is OK, type reboot at the prompt and then press Return.
    Your computer should start up normally and allow you to log in.

  • How to enforce index in oracle query

    Hi all
    how to enforce index in oracle query
    Regards

    Use INDEX hint to force Optimizer to use the specfied index.
    You really need to investigate why Optimizer doesn't choose the index. Remember, INDEX SCAN are not always GOOD.
    Jaffar

  • HT1688 how to do factory unlock for my  iphone4? Now i use another country carrier so please tell me how to do that .

    how to do factory unlock for my  iphone4? Now i use another country carrier so please tell me how to do that .

    how to do please explain me . i live from myanmar so this case is difficult and i don`t know original cellular provider

  • How to use factory calender in BPM (NWDS 7.1 environement )

    hi guys,
    I have requirement to send u201Cnotification of missed deadlineu201D using factory calendar.
    The time to send notification is in hours and its is less than a day. So a task created on Friday 5u2019o clock should send missed alert on Monday 9 AM (assuming business run from 9 to 5).
    this need to be achieve using BPM workflow can any suggest me how to use factory calendar in BPM .

    Hi,
    You can use "BUSINESS_DATE_CREATE" function module in the ECC system for your requirement.
    This will calculate exact date and time and return next business day.
    You need to some datetime convertions on the BPM side to get it working
    Regards, Anil

  • How to enforce index

    Hi Guys,
    How to enforce index ?
    Say for example,
    select max(dt) from emp
    emp table has an index called 'id1'.
    I want to enforce this index for the above query. How ?
    Inputs are welcome !

    Your index on ID is worthless for this query.
    You would have to add an index on your DT column. Even then, the index will only be used if you have a NOT NULL constraint on the column (or add "and dt is not null" to your query):
    SQL> explain plan for
      2  select min(dt), max(dt) from emp;
    Explained.
    | Id  | Operation            |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |             |     1 |     8 |   194 |
    |   1 |  SORT AGGREGATE      |             |     1 |     8 |       |
    |   2 |   TABLE ACCESS FULL  | EMP         | 91000 |   710K|   194 |
    SQL> alter table emp modify (dt not null);
    Table altered.
    SQL> explain plan for
      2  select min(dt), max(dt) from emp;
    Explained.
    | Id  | Operation             |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT      |             |     1 |     8 |    39 |
    |   1 |  SORT AGGREGATE       |             |     1 |     8 |       |
    |   2 |   INDEX FAST FULL SCAN| EMP_DT      | 91000 |   710K|    39 |
    ---------------------------------------------------------------------Still, even without an index a full table scan of 91000 rows takes < 1 second even on my laptop. How are you getting 21 seconds?

  • How to enforce the message "Do you want to save changes?"

    Hello,
    How to enforce the message "Do you want to save changes?" when the user attempts to close a form after checking a non-database item (check-box).
    All the other database items in the block are not updateable and only viewable.
    After checking the non database item check-box, if the user tries to commit, then the system is saving the changes and call the appropriate procedure on save.
    But if the user tries to close the window without committing, the form is not showing the message "Do you want to save changes?" since the check-box is a non database item.
    How to enforce the message "Do you want to save changes?" in this scenario when the user tries to close the window?
    Thanks in advance.
    Cheers
    Sri

    This is a fairly common question in the forum. You will need to override the default exit form process and check to see if the checkbox is checked. You can do this in the Key-Exit trigger. For Example:
    DECLARE
      al_id     ALERT;
      al_button  NUMBER;
    BEGIN
      IF ( CHECKBOX_CHECKED('YOUR_BLOCK.CHECKBOX_ITEM') ) THEN
         /* Display an Alert here that asks, "Do you want to save changes?" */
         ...code here to set the properties of your alert...
         al_button := Show_Alert(al_id);
         IF ( al_button = ALERT_BUTTON1 ) THEN
            --YES
            /* Perform COMMIT Processing here...*/
         ELSIF ( al_button = ALERT_BUTTON2 ) THEN
            --No
            Exit_Form(NO_VALIDATE);
         ELSE
            --Cancel
            RAISE Form_Trigger_Failure;
         END IF;
      ELSE
         Exit_Form;
      END IF;
    END;If you need more help with the Alert, please check out the SHOW_ALERT topic in the Forms Help.
    BTW, what happens if all the user does is check the checkbox? No other changes have occured. What changes are you trying to process?
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • How to extend factory calender to a plant ?

    Hi Ranga:
    How to extend factory calender to a plant ? ( Tcode: SCAL, The calender is not client specific)
    I check marked US factory calender, where after can you tell how to extend factory calender to plant
    Note: I am using IDES ( International Demonstration & Education System)
    Thanks

    Hi Sandeep,
    you need to use the following path
    Go to SPRO>ENTERPRISE STRUCTURE->DEFINITION> LOG GENERAL>DEFINE COPY,DELETE AND CHECK PLANT>DEFINE PLANT
    Here you need to assign the factory calendar. The assignment in work center will only applicable for capacity not for MRP and others.
    <b>For information how to create a factory calendar</b>
    Pl follow the steps
    1.Go to SCAL transaction
    2.there will be three options.
    Click first public holidays and go in change mode.
    Click create and create your holidays there and save.(Generally fixed date will be used in the pop up)
    3.Now click Holiday calendar and go in change mode.
    Click create and give holdiay cal id and description.
    Click assign public holiday and add your holidays one by one and save
    Now holiday cal is created.
    4.Now come out and choose fact calendar and go in change mode
    Click create and give Factory calendar id and description, and validity period.
    Give the holiday calendar ID.
    If you want to give special rule like any of the specific date/ day is the holiday or work day (which is different from holiday calendar you can define)
    and save.
    5.You have to assign factory calendar to PLANT
    Go to SPRO>ENTERPRISE STRUCTURE->DEFINITION> LOG GENERAL>DEFINE COPY,DELETE AND CHECK PLANT>DEFINE PLANT
    Choose your plant and go to details-
    You have to define factory calendar there
    Hope this will help you
    Regards
    Ranga

  • How can i factory unlock iphone 4

    how can i factory unlock iphone 4

    ONLY the carrier to which it is locked can unlock it.  No one else.
    Contact that carrier and see if they offer this service and if you qualify.

  • How can i factory unlocked an iphone 3gs.

    how can i factory unlocked an iphone 3gs.
    iPhone 3GS

    Contact the carrier to which the iPhone is locked. Only the carrier can authorize unlocking.

  • How can i factory unlock my iphone 5c ? its carrier is atnt

    how can i factory unlock my iphone 5c? its carrier is atnt and i want to be able to use it in south america using a gsm sim

    "Factory unlock" would mean that the iPhone would have come from Apple unlocked. You mean "officially unlocked", meaning the unlocking has been approved by the carrier. Here are AT&T's official requirements for unlocking an iPhone:
    http://www.att.com/esupport/article.jsp?sid=KB414532&cv=820#fbid=7eivX4S6I8c
    and the procedure:
    https://www.att.com/deviceunlock/client/en_US/
    Regards.

  • How to restore factory settings iphone 4

    how to restore factory settings iphone 4

    Well, just have the iPhone turned off and connected to the computer, and then hold the home screen button with itunes open for 10 seconds. It will recognize it, and you can just hit restore.
    And I would like to share you below articles about restore data from iPhone:
    * How to restore iPhone from iTunes backup files
    * How to put your iPhone into DFU Mode for Restore

  • HT1655 I have a 3rd generation shuffle.  It has stopped working with the earphones it came w/pinch buttons on the cord.  It will no longer advance to next song/change the volume.  Even with a new set of Apple earbuds, it does same thing.  How do i factory

    I have a 3rd generation shuffle.  It has stopped working with the earphones it came w/pinch buttons on the cord.  It will no longer advance to next song/change the volume.  Even with a new set of Apple earbuds, it does same thing.  How do i factory reset or fix the problem?

    Hello there, RufusChloe.
    The following iPod Troubleshooting Assistant should help with troubleshooting your issue:
    Apple - Support - iPod - iPod shuffle (3rd generation) Troubleshooting
    http://www.apple.com/support/ipod/five_rs/shuffle3gen/
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • How to enforce uniqueness to my database table

    Hello
    One of my database will be updated based on two columns c1 and c2.
    Previous i created an index on these two columns. But forgot to enforce uniqueness. Now my table has some duplicate data.Means columns c1 and c2 contained same value for more than one record. Now i deleted all the duplicate data. And i also want to allow any duplicate data into my table in future. While i was creating an unique index on these two columns it is not allowing and prompting errors. Can someone guide me how to enforce uniqueness for my table

    And i also want to allow any
    duplicate data into my table in future.
    Can someone guide
    me how to enforce uniqueness for my tableSo you want to enforce uniqueness or not?
    Look at alter table add constraint clause in sql reference manual.
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/clauses002.htm#g1053592
    In case you have duplicate values you can
    "ENABLE NOVALIDATE ensures that all new DML operations on the constrained data comply with the constraint. This clause does not ensure that existing data in the table complies with the constraint and therefore does not require a table lock."
    Gints Plivna
    http://www.gplivna.eu

  • Urgent    how to change factory calender to normal calender  in bw report

    Hi
    how to change factory calender to normal calender  in bw report give me step by step
    prasanth.k

    Prasanth,
    the calenders are maintained in the source system and not in BW - if you have to change the calendar coming into BW - do the needful change for the related transaction in the source system.
    Arun

Maybe you are looking for

  • Windows 8 App Deployment in School Lab environment?

    After doing some reading and research on Windows 8 Store app deployment from sources like http://www.microsoft.com/en-us/download/details.aspx?id=39685 and this forum and I am getting pretty depressed.  Here is one part of my scenario which is pretty

  • Amazon Prime instant video using home sharing

    I have an IPad 1 and Apple TV.  I would like to view instant streaming videos from Amazon Prime, but only get audio not video through home sharing. Does anyone know a way to fix that?

  • Flash hyperlinks not working when hosted

    Hey all.  I've recently run into an issue with Adobe Flash Professional using Actionscript3 to navigate to separate pages on my personal webpage.  I believe I have the coding correct because when I open it locally in my browser, the links all work pe

  • Restrict the Quantity in the Scheduling Agreement

    Dear All, I have a scenario where the client wants to restrict the quantity in scheduling agreement for particular customer. Scenario: Scheduling Agreement(Valid: 01.04.2011 to 31.03.2012) should be created for XYZ customer with target qty as 3000 pe

  • MuVo N200 problem with playba

    I have an older MuVo N200. I have transferred some of my class notes to it and it had done just fine so I transferred some musice to it as well. It played back very well for about 2 days and now it is just a high pitch squelling:angry:. I have lost s