Factory Method Example Program in Java

 /*  
 Factory method is just a fancy name for a method that instantiates objects.   
 Like a factory, the job of the factory method is to create -- or manufacture   
 -- objects.   
 author:itsafiz@gmail.com  
 */  
 class FactoryMethod  
 {  
      static FactoryMethod obj=null;   
      static FactoryMethod getMethod()  
           {  
                System.out.println("getMethod");  
                return obj;   
           }  
      static FactoryMethod setMethod()  
           {  
                System.out.println("setMethod");  
                return obj;   
           }  
 }  
 class FactoryMethodTest // main class   
 {  
      public static void main(String[]args)  
      {  
            FactoryMethod obj1=FactoryMethod.getMethod();   
            FactoryMethod obj2=FactoryMethod.setMethod();                  
      }  
 }  

Post a Comment

1 Comments

  1. Is this really Factory method pattern impl?

    ReplyDelete