Static factory methods, instead of constructor

Hi All,
why we use static factory methods, instead of constructor.
Apart from Singleton class , what is use of static factory methods ?
Thanks in Advance,
Rishi

One reason for using factories is that they simplify creating instances of immutable classes that might otherwise have messy constructors with lots of arguments.

Similar Messages

  • [svn:osmf:] 10996: Changing MediaElementLayoutTarget to be constructed via a static ' getInstance' method, instead of by its constructor.

    Revision: 10996
    Author:   [email protected]
    Date:     2009-10-19 07:45:26 -0700 (Mon, 19 Oct 2009)
    Log Message:
    Changing MediaElementLayoutTarget to be constructed via a static 'getInstance' method, instead of by its constructor. This prevents the construction of multiple instances that reference one single media-element. Updating client code accordingly.
    Extending layout unit tests. Adding a custom renderer, checking calculation and layout passes invokation counts.
    Modified Paths:
        osmf/trunk/framework/MediaFramework/org/osmf/composition/CompositeViewableTrait.as
        osmf/trunk/framework/MediaFramework/org/osmf/composition/ParallelViewableTrait.as
        osmf/trunk/framework/MediaFramework/org/osmf/composition/SerialViewableTrait.as
        osmf/trunk/framework/MediaFramework/org/osmf/gateways/RegionSprite.as
        osmf/trunk/framework/MediaFramework/org/osmf/layout/DefaultLayoutRenderer.as
        osmf/trunk/framework/MediaFramework/org/osmf/layout/LayoutContextSprite.as
        osmf/trunk/framework/MediaFramework/org/osmf/layout/LayoutRendererBase.as
        osmf/trunk/framework/MediaFramework/org/osmf/layout/MediaElementLayoutTarget.as
        osmf/trunk/framework/MediaFramework/org/osmf/utils/MediaFrameworkStrings.as
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/composition/TestParallelViewableTrai t.as
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/gateways/TestRegionSprite.as
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/layout/TestDefaultLayoutRenderer.as
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/layout/TestLayoutUtils.as
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/layout/TestMediaElementLayoutTarget. as
    Added Paths:
        osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/composition/CustomRenderer.as

    AlexCox, can you clarify that once you get the default model out and save it in the temp var, that your ONLY access to the data is then through temp and never through the JList methods?
    Quick question for everyone: Are any of you using JList.setListData to set you initial dataset? I think that is where the bug lies. When I do not use it and start with an empty list, I am able to add to that list, and then remove from that list using the following line:
    ((DefaultListModel)myList.getModel).remove(###);
    And this cast works everytime.
    But when I start that list out with some data such as:
    myList.setListData(myStringArray);
    and then try to execute the above line, boom! I get the ClassCast exception.
    I think setListData creates a whole new model which is an inner class to JList (which seems stupid when DefaultListModel seems made for this).
    Just my thoughts on where the problem lies. I'll add my data directly to the list and see if that works better.
    PK

  • Static Factory Methods

    can anybody guide me on what static factory methods are, how they are invoked and there advantages over constructors.

    Joshua Bloch has a good bit on it in his book Effective Java. If you don't have that then I suggest Google as it's been explained to death before. Static factory methods are for all intents and purposes when you provide a static method that returns an instance of a given object rather than having a public constructor.

  • Calling static synchronized method in the constructor

    Is it ok to do so ?
    (calling a static synchronized method from the constructor of the same class)
    Please advise vis-a-vis pros and cons.
    regards,
    s.giri

    I would take a different take here. Sure you can do it but there are some ramifications from a best practices perspective. f you think of a class as a proper object, then making a method static or not is simple. the static variables and methods belong to the class while the non-static variables and methods belong to the instance.
    a method should be bound to the class (made static) if the method operates on the class's static variables (modifies the class's state). an instance object should not directly modify the state of the class.
    a method should be bound to the instance (made non-static) if it operates on the instance's (non-static) variables.
    you should not modify the state of the class object (the static variables) within the instance (non-static) method - rather, relegate that to the class's methods.
    although it is permitted, i do not access the static methods through an instance object. i only access static methods through the class object for clarity.
    and since the instance variables are not part of the class object itself, the language cannot and does not allow access to non-static variables and methods through the class object's methods.

  • Why do we use init() method instead of constructor to initialize a servlet?

    Why do we use init() method instead of constructor to initialize a servlet?

    I suspect the reasons are partly historical. A servlet is loaded dynamically, by class name and, once you've loaded the Class, it's easier to to a newInstance, using the default construtor than it is to search for a particular matching constructor and invoke it.

  • Apply static method requirements on class (Static interface methods)?

    I have a set of classes where is class is identified with a unique ID number. So each class has a public static int getId() method. Each class also has either a constructor that takes a byte array or a static factory method that takes a byte array.
    I would like to maintain a hashmap of these classes keyed to the ID's however I am not sure how to have some interface of abstract parent class that requires each of these classes to implement these static methods.
    What I was hoping to do was something like this>>>
         public interface MyClasses{
              static MyClasses createInstance(byte[] data);
         HashMap<Integer, MyClasses> map;
         public void init() {
              map = new HashMap<Integer, MyClasses>();
              map.put(Class1.getId(), Class1.class);
              map.put(Class2.getId(), Class2.class);
         public void createInstance (int id, byte[] data) {
              map.get(id).createInstance(data);
         }Is there some way I could do this?

    What about something like this?
    public interface Initializable
         public void initialize(byte[] data);
    public class Factory
         private final Map<Integer, Initializable> map = new HashMap<Integer, Initializable>();
            public void registerClass(int id, Class klass)
                    if (! Initializable.class.isAssignableFrom(klass))
                             // you may also want to ensure the class declares a parameterless constructor
                             throw new IllegalArgumentException("duff class");
                    if (this.map.keySet().contains(id))
                             throw new IllegalArgumentException("duff id");
              this.map.put(id, klass);
         public Initializable createInstance(int id, byte[] data)
                    // need some exception handling of course
              Initializable i = map.get(id).newInstance();
                    i.initialize(data);
                    return i;
    }

  • Why init() instead of constructor

    why we are using init method instead of constructor to initialise a servlet? pls any bosy tell me

    Before a servlet can be loaded, the servlet engine must first locate its class.Once loaded, the servlet engine instantiates an instance of that servlet class. An instantiated servlet must be initialised before it is ready to receive client requests.The Servlet API provides the init() callback method for a servlet to place all its initialisation logic. Once a servlet has been instantiated the init() is invoked by the servlet engine to initialise the servlet for the first time only.

  • Constructor or factory method?

    Hi!
    This is probebly a wery simple problem but i havn't found a good answer.
    I have a class that read/write to a specified file on disk. If an object hasn't existed before i want to pas a filename to create the object. When the object has already existed and already has an file on disk i also whant to get an instance of the object by passing in a file.
    Both cases the constructor taks the same argument but i realy need tow seperate constructors. What should i do? Is there any pattern on this issue? Maby one of the constructors should be a factory method?
    Thanks!
    /Christer

    If I am understanding you question correctly, you definitely want a factory. Don't have any public constructors. Here's an example that you can adapt as needed.
    public final class FileFactory
       private static final Map files = new HashMap();
       private FileFactory(){}
       public static File getFile(String name)
          File file = files.get(name);
          if (file == null)
             file = new File(name);
             files.put(name, file);
          return file;
    }If you want to sometimes return an existing instance, a constructor cannot possibly work for you. Constructors only return new instances.

  • Could someone explain the Factory Method Design Pattern

    Hi Experts.
    Could someone please explain for me the Factory Method Design Pattern. I read it a little and I understand that it is used in JDBC drivers but i'm not clear on it.
    Could someone explain.
    Thanks in advance
    stephen

    Basically, you have one class that's sole purpose is to create instances of a set of other classes.
    What will usually happen is you have a set of related classes that inherit from some base class. We'll say for example that you have a base class CAR and it has sub-classes FORD, GM, HONDA (sorry Crylser). Instead of having the user call the constructors for FORD, GM, and HONDA, you can give the user a Factory Class that will give him a copy. We'll call our factory class Dealership. Inside dealership, you can have a static function :
    public static Car makeCar(String type)
    if(type.equals("FORD")
    return new FORD();
    else if(type.equals("GM")
    return new GM();
    else if(type.equals("HONDA")
    return new HONDA();
    So when the user needs a car, they will just call
    Dealership.makeCar("FORD").
    This is a good way to hide the implementation of your classes from the user, or if you require complex initialization of your objects.
    Another good example of this is in the Swing library. To get a border around a component, you call static methods on BorderFactory.
    Hope this helped.
    Ed

  • Problem in factory method, how to pass arguments ?

    Hello it's me again :)
    here's the code :
    package print;
    import java.util.*;
    import static print.Print.*;
    interface Fact<T> {
    T create(String n);;
    T create ();
    class PetColl {
          public String toString() {
          return getClass().getSimpleName();
          static List<Fact<? extends Pet>> petSpecies=
          new ArrayList<Fact<? extends Pet>>();
          static {
          // Collections.addAll() gives an "unchecked generic
          // array creation ... for varargs parameter" warning.
               petSpecies.add(new Cymric.Factory());
               petSpecies.add(new EgyptianMau.Factory());
               petSpecies.add(new Hamster.Factory());
               petSpecies.add(new Manx.Factory());
               petSpecies.add(new Mouse.Factory());
               petSpecies.add(new Pug.Factory());
               petSpecies.add(new Mutt.Factory());
               petSpecies.add(new Rat.Factory());
          private static Random rand = new Random(47);
          public static Pet createRandom() {
          int n = rand.nextInt(petSpecies.size());
          return petSpecies.get(n).create();
          public Pet[] createArray(int size) {
               Pet[] result = new Pet[size];
               for(int i = 0; i < size; i++)
               result[i] = createRandom();
               return result;
          public ArrayList<Pet> arrayList(int size) {
               ArrayList<Pet> result = new ArrayList<Pet>();
               Collections.addAll(result, createArray(size));
               return result;
    class Individual implements Comparable<Individual> {
         private static long counter = 0;
         private final long id = counter++;
         private String name;
         public Individual(String name) { this.name = name; }
         // ?name? is optional:
         public Individual() {}
         public String toString() {
         return getClass().getSimpleName() +
         (name == null ? "" : " " + name);
         public long id() { return id; }
         public boolean equals(Object o) {
         return o instanceof Individual &&
         id == ((Individual)o).id;
         public int hashCode() {
         int result = 17;
         if(name != null)
         result = 37 * result + name.hashCode();
         result = 37 * result + (int)id;
         return result;
         public int compareTo(Individual arg) {
         // Compare by class name first:
         String first = getClass().getSimpleName();
         String argFirst = arg.getClass().getSimpleName();
         int firstCompare = first.compareTo(argFirst);
         if(firstCompare != 0)
         return firstCompare;
         //second compare by name
         if(name != null && arg.name != null) {
         int secondCompare = name.compareTo(arg.name);
         if(secondCompare != 0)
         return secondCompare;
         }//third compare by id
         return (arg.id < id ? -1 : (arg.id == id ? 0 : 1));
    class Pets {
          public static final PetColl creator =
          //new LiteralPetCreator();
               new PetColl();
          public static Pet randomPet() {
          return creator.createRandom();
          public static Pet[] createArray(int size) {
          return creator.createArray(size);
          public static ArrayList<Pet> arrayList(int size) {
          return creator.arrayList(size);
    class Person extends Individual {
    String name;
    public static class Factory implements Fact<Person>{
    public Person create(String name){
         Person.name=name;
         return new Person(); }
    public Person create(){return new Person();}
    class Pet  extends Individual {
    class Dog extends Pet {
    class Mutt extends Dog {
          public static class Factory implements Fact<Mutt> {
               public  Mutt create(String name){return new Mutt(name);}
               public  Mutt create () {return new Mutt();}
    class Pug extends Dog {
          public static class Factory implements Fact<Pug> {
               public  Pug create(String name){return new Pug(name);}
               public  Pug create () {return new Pug();}
    class Cat extends Pet {
    class EgyptianMau extends Cat {
          public static class Factory implements Fact<EgyptianMau> {
               public  EgyptianMau create(String name){return new EgyptianMau(name);}
               public  EgyptianMau create () {return new EgyptianMau();}
          class Manx extends Cat {
               public static class Factory implements Fact<Manx> {
                    public  Manx create(String name){return new Manx(name);}
                    public  Manx create () {return new Manx();}
         class Cymric extends Manx {
              public static class Factory implements Fact<Cymric> {
                    public  Cymric create(String name){return new Cymric(name);}
                    public  Cymric  create () {return new Cymric();}
    class Rodent extends Pet {
    class Rat extends Rodent {
          public static class Factory implements Fact<Rat> {
               public  Rat create(String name){return new Rat(name);}
               public  Rat create () {return new Rat();}
    class Mouse extends Rodent {
          public static class Factory implements Fact<Mouse> {
               public  Mouse create(String name){return new Mouse(name);}
               public  Mouse create () {return new Mouse();}
    class Hamster extends Rodent {
          public static class Factory implements Fact<Hamster> {
               public  Hamster create(String name){return new Hamster(name);}
               public  Hamster create () {return new Hamster();}
    public class Test {
          public static void main(String[] args) {
              for(Pet p:Pets.creator.arrayList(25)){
          PetCount.petC.count(p.getClass().getSimpleName());
              print(p.getClass().getSimpleName());}
      class PetCount {
          static class PetCounter extends HashMap<String,Integer> {
          public  void count(String type) {
          Integer quantity = get(type);
          if(quantity == null)
          put(type, 1);
          else
          put(type, quantity + 1);
         public static PetCounter petC= new PetCounter();
      }and here's my problem:
    I'm trying to fill up list using factory method but in a fact that I want to have two constructors, I have a problem to set field name of objects of those classes. Is there any possibility to use in that way some factory method to create that list ?
    In Person class I've tried to set it in factory method before creating an object, but as you know that option is only alvailable for static fields which i don't want to be static.

    I for one have no idea what you're asking, and what you seem to be saying doesn't make sense.
    I'm trying to fill up list using factory method but in a fact that I want to have two constructors,Two constructors for what? The factory class? The classes that the factory instantiates?
    I have a problem
    to set field name of objects of those classes. Is there any possibility to use in that way some factory method to
    create that list ?What?
    In Person class I've tried to set it in factory method before creating an object, but as you know that option is only alvailable for static fields which i don't want to be static.That doesn't make any sense. A Factory can easily set fields in the objects it creates on the fly (not static).

  • Factory method

    Hey all, I am tying to learn factory method and working on an example from the Oreilly AS3 Design patterns book. I am attempting figure out how all the classes work together in this design pattern and I have a question I am hoping someone might be able clearify for me.
    In the document class "Main"  I have the following code in the constructor
    // instantiate concrete shape creators
    var unfilledShapeCreator:ShapeCreator = new UnfilledShapeCreator( );
    // draw unfilled shapes  NOTE: draw() is a method of the ShapeCreator class
    unfilledShapeCreator.draw(UnfilledShapeCreator.CIRCLE, this.stage, 50, 75);
    I get what is going on there, so I open up the 'UnfilledShapeCreator" class and it has the following:
    package shapecreators
         /* Concrete Creator class */
         public class UnfilledShapeCreator extends ShapeCreator
              public static const CIRCLE :uint = 0;
              public static const SQUARE :uint = 1;
              //implement the createShape factory method from the ShapeCreator Class.
              override protected function createShape(cType:uint):ShapeWidget
                   if (cType == CIRCLE)
                        trace("Creating new circle shape");
                        return new CircleWidget( ); //Instantiates circleWidge Product Class
                   } else if (cType == SQUARE) {
                        trace("Creating new square shape");
                        return new SquareWidget( ); //Instantiates square Widge Product Class
                   } else {
                        throw new Error("Invalid kind of shape specified");
                        return null;
    and the ShapeCreator class is as follows
    package shapecreators
         /* Defines the abstract interface for the creator classes */
         import flash.display.DisplayObjectContainer;
         import flash.errors.IllegalOperationError;
         // ABSTRACT Class (should be subclassed and not instantiated)
         public class ShapeCreator
              public function draw(cType:uint, target:DisplayObjectContainer, xLoc:int, yLoc:int):void
                   var shape = this.createShape(cType);
                   shape.drawWidget( );
                   shape.setLoc(xLoc, yLoc); // set the x and y location
                   target.addChild(shape); // add the sprite to the display list
              // ABSTRACT Method (must be overridden in a subclass)
              protected function createShape(cType:uint):ShapeWidget
                   throw new IllegalOperationError("Abstract method: must be overridden in a subclass");
                   return null;
    My question is: how does the cType  parameter get passed into the createShape method?  This method does not seem to get called from anywhere or any other class.   I see how FilledShapeCreator.CIRCLE gets passed to the  draw method in the ShapeCreator class, but the createShape method is never called like the draw method is.
    Is it because createShape is called within the draw function?
    I am quite sure it is a simple answer, but it has me completely lost.
    Thanks,

    Yes, it is called by super class in line:
    var shape = this.createShape(cType);
    By the way, I don't know where you got code but it is a pretty bad practice not type variables. Good compiler should not even allow you to compile. The line above should be:
    var shape:ShapeWidget = this.createShape(cType);

  • Factory method usage, creating the correct Image subclass

    Hi, I created a factory method
      public enum ImgType {
        SINGLE, STRIP, SPRITE_SHEET
    public static Image createImage(ImgType imgType) {
        switch (imgType) {
          case SINGLE:
            return new MyImage1(0, 0);
          case SPRITE_SHEET:
            return new MyImage2("", 0, 0);
          case STRIP:
            return new MyImage3("", 0, 0);
          default:
            throw new IllegalArgumentException("The image type " + imgType + " is not recognized.");
      }that creates different images based on the enum type provided.
    and heres is a usage of that function
      public BufferedImage loadAwtImage(ImageInputStream in, String imgName,  ImageTypeFactory.ImgType imgType) throws IOException {
        BufferedImage img = imgLoader.loadImage(in);
        BufferedImage imgsubType = ImageTypeFactory.createImage(imgType);  // Convert to real Image type
        addAwtImg(imgName, imgsubType);
        return imgsubType;
      }In a test:
    imgLib.loadAwtImage(imageStream, "cursor", ImageTypeFactory.ImgType.SPRITE_SHEET);Is it 'good' that in the test I can say(using the imgType enum) what sort of Image should be returned?
    doesn't this expose the working of the class to the outside, on the other hand I don't know howto create the correct sub image based on an image loaded.
    I use subImages to allow selection within the image, like the 3th 'tile' within an imageStrip returns just that cropped image.
    Before I had List<Image> and List<List<Image>> and now I can just return Images in 1 method instead of 2,3 by using lists.
    Edited by: stef569 on Dec 12, 2008 11:05 AM

    creates specifications... :p
    *  load the BufferedImage from the ImageInputStream
    * add it to the cache keyed by the imgName
    * @return a BufferedImage, or a custom subclass based on the imgType
    * @throws IOException when the img could not be loaded
    public BufferedImage loadAwtImage(ImageInputStream in, String imgName,  ImageTypeFactory.ImgType imgType) throws IOException I can test it, but the ImageTypeFactory.ImgType imgType parameter looks wrong to me.
    if you see this in a class method would you change it/find a better way.

  • Static Classes/Methods vs Objects/Instance Classes/Methods?

    Hi,
    I am reading "Official ABAP Programming Guidelines" book. And I saw the rule:
    Rule 5.3: Do Not Use Static Classes
    Preferably use objects instead of static classes. If you don't want to have a multiple instantiation, you can use singletons.
    I needed to create a global class and some methods under that. And there is no any object-oriented design idea exists. Instead of creating a function group/modules, I have decided to create a global class (even is a abstract class) and some static methods.So I directly use these static methods by using zcl_class=>method().
    But the rule above says "Don't use static classes/methods, always use instance methods if even there is no object-oriented design".
    The book listed several reasons, one for example
    1-) Static classes are implicitly loaded first time they are used, and the corresponding static constructor -of available- is executed. They remain in the memory as long as the current internal session exists. Therefore, if you use static classes, you cannot actually control the time of initialization and have no option to release the memory.
    So if I use a static class/method in a subroutine, it will be loaded into memory and it will stay in the memory till I close the program.
    But if I use instance class/method, I can CREATE OBJECT lo_object TYPE REF TO zcl_class then use method lo_object->method(), then I can FREE  lo_object to delete from the memory. Is my understanding correct?
    Any idea? What do you prefer Static Class OR Object/Instance Class?
    Thanks in advance.
    Tuncay

    @Naimesh Patel
    So you recommend to use instance class/methods even though method logic is just self-executable. Right?
    <h3>Example:</h3>
    <h4>Instance option</h4>
    CLASS zcl_class DEFINITION.
      METHODS add_1 IMPORTING i_input type i EXPORTING e_output type i.
      METHODS subtract_1 IMPORTING i_input type i EXPORTING e_output type i.
    ENDCLASS
    CLASS zcl_class IMPLEMENTATION.
      METHOD add_1.
        e_output = i_input + 1.
      ENDMETHOD.
      METHOD subtract_1.
        e_output = i_input - 1.
      ENDMETHOD.
    ENDCLASS
    CREATE OBJECT lo_object.
    lo_object->add_1(
      exporting i_input = 1
      importing e_output = lv_output ).
    lo_object->subtract_1(
      exporting i_input = 2
      importing e_output = lv_output2 ).
    <h4>Static option</h4>
    CLASS zcl_class DEFINITION.
      CLASS-METHODS add_1 IMPORTING i_input type i EXPORTING e_output type i.
      CLASS-METHODS subtract_1 IMPORTING i_input type i EXPORTING e_output type i.
    ENDCLASS
    CLASS zcl_class IMPLEMENTATION.
      METHOD add_1.
        e_output = i_input + 1.
      ENDMETHOD.
      METHOD subtract_1.
        e_output = i_input - 1.
      ENDMETHOD.
    ENDCLASS
    CREATE OBJECT lo_object.
    lo_object->add_1(
    zcl_class=>add_1(
      exporting i_input = 1
      importing e_output = lv_output ).
    lo_object->subtract_1(
    zcl_class=>subtract_1(
      exporting i_input = 2
      importing e_output = lv_output2 ).
    So which option is best? Pros and Cons?

  • Factory method generateRandomCircle: "cannot resolve symbol"

    I have written 2 classes: Point and Circle, which uses Point objects in order to create a Circle object. I have created a factory method for Point, which creates random Point objects and a for Circle, which does the same. "newRandomInstance" works fine for Point, but "generateRandomCircle" throws a "cannot resolve symbol" error. "main" is inside Point class. What's the problem?
    Thanks
    ================================================
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    public class Circle implements Cloneable
    public static Circle generateRandomCircle()
    int a= (int) (Math.random()* Short.MAX_VALUE);
    int b= (int) (Math.random()* Short.MAX_VALUE);
    Point p=new Point(a,b);
    int r= (int) (Math.random()* Short.MAX_VALUE);
    Circle c= new Circle(p,r);
    return c;
    ===============================================
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    public class Point implements Cloneable, Comparable
    public static Point newRandomInstance()
    int x = (int) (Math.random() * Short.MAX_VALUE);
    int y = (int) (Math.random() * Short.MAX_VALUE);
    return new Point(x,y);
    public static void main (String[] args)
    Circle cRandom= generateRandomCircle(); //doesn't work
    System.out.println(cRandom.getCenter()+" "+ cRandom.getRadius());
    Point randomP= newRandomInstance(); //works OK
    randomP.printPoint();
    }

    I tried "Circle cRandom=
    Circle.generateRandomCircle(); " instead of "Circle
    cRandom= generateRandomCircle();" and it worked. Why
    did this happen?Because generateRandomCircle() exists in class Circle and not in class Point where your are trying to use it.
    >
    Function "newRandomInstance()" works either as
    "Point.newRandomInstance()" or as
    "newRandomInstance()", however. Why does this
    controversy exist?No controversy! Your main() is contained within class Point and as such knows about everything that is declared in class Point() but nothing about what is in class Circle unless you tell it to look in class Circle.

  • What is a Factory method and when to use this concept?

    Could any one please describe what a factory method is and explain how I can use it by giving a simple example

    A Factory Method (sometimes called a "virtual constructor") is a way to avoid hard coding what class is instantiated. Consider:
    DataSource myDataSource = new DataSource();Now, if you want to use some other DataSource in your app, say, an XMLDataSource, then you get to change this code and all subsequent lines that use this, which can be a lot. If, however, you specified and interface for your DataSources, say, IDataSource, and you gave the DataSource class a static "create" method that would take some indication of what sort of DataSource to actually use, then you could write code like:
    IDataSource myDataSource = DataSource.create(dataSourceString);And be able to pass in a dataSourceString describing what DataSource you wanted to use - and not have to recompile. Check out the Java Design Patterns site ( http://www.patterndepot.com/put/8/JavaPatterns.htm )
    Make sense?
    Lee

Maybe you are looking for

  • Problem with full screen playback

    Everything works fine until I go to preview in full screen. I hit the space bar to play the viewer and nothing happens. If I move the mouse over to where the play button is in the viewer window before the screen goes full and click where it was, it w

  • How do I create a Dynamic java.sql.Date ArrayList or Collection?

    I Have a MySQL table with a Datetime field with many values inserted. I want to know which is the Best way to capture all the Inserted DB values inside a Dynamic Array. I get errors that state that I should use Matching data-types, and plus I don't k

  • Mass upload of BOM for Equipment & Functional Locations

    Dear Gurus, I have an existing system with Functional Locations & Superior Functional Locations, Equipments with Superior equipments. I need to update the BOM for all (most) of these. Can we do it through LSMW or any other Mass update transactions??

  • Difference in sharing between 2003, 2008 and 20012

    Hi, We have a Dell 3115cn printer. This printer is able to scan a doc to a share, SMB Port 139. When I create a share on a Windows 2003 or Windows 2008 server, there is no problem scanning to this share. But on a 2012 server the printer is not able t

  • [SOLVED] Problems with systemd-update-utmp after systemd update

    Hi all, I noticed that systemd-update-utmp-runlevel.service has been failing since the last systemd update. My systemd is: Repository : core Name : systemd Version : 184-2 $ systemctl status systemd-update-utmp-runlevel.service systemd-update-utmp-ru