Results 1 to 3 of 3
  1. #1
    prabhurangan is offline Member
    Join Date
    May 2008
    Rep Power

    Default Factory loading

    Hi Members,

    Hope you would be doing great. And coming to my topic.

    I have a factory loading class, on changing my input parameter factory loading has to be done.

    My code:
    // instance declaration
    Line 1: private static BugTrackerFactory instance;

    Line 2: public static synchronized FactoryClass getInstance(String className)
    Line 3: {
    Line 4: //instance = null; (
    Line 5: //only if 'instance' is == 'null', it creates a new instance
    Line 6: if ( instance == null )
    Line 7: {

    Line 8: instance = new FactoryClass(className); // constructor call with single argument
    Line 9: }

    return instance;

    Note: here in this code, when i change the className(input parameter), with the new class name, the instance is not getting 'null', instead it is holding the instance of the previous class. For this i have declared the instance as 'null', in the code(line number 4), within the constructor method... is it right way of coding.

    Please do suggest me some useful tips in this.


  2. #2
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Rep Power


    please specify the Whole code .. i think the static is the culprit and i can see you have commented line 4 is it same in the code too.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    On vacation
    Rep Power


    You have coded a singleton pattern class. Only ONE instance of the class is supposed to be created.
    What do you intend to happen?
    The arg className does NOT have any influence on whether a new instance is created.

Similar Threads

  1. Loading a class within a different class
    By nick2price in forum New To Java
    Replies: 1
    Last Post: 05-30-2008, 07:19 AM
  2. Help with class loading in java
    By mathias in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 08:51 PM
  3. Secure FTP Factory 7.0
    By vglass in forum Java Software
    Replies: 0
    Last Post: 07-20-2007, 01:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts