{{theTime}}

Search This Blog

Total Pageviews

Abstract Factory Design Pattern Implementation with Example

Abstract Factory Design Pattern:  
 
-- Encapsulate a group of factories without specifying concrete classes.

Example implementation of IntelProcessor in various electronic products.

public interface IntelProcessor {
  public void implementProcessor() ;
  public void setProcessorName()
}

public SmartPhone implements IntelProcessor {
  public void implementProcessor() {}
  public void setProcessorName() {}
}

public Laptop implements IntelProcessor {
  public void implementProcessor() {}
  public void setProcessorName() {}
}

public interface AbstractProcessorFactory() {
   public IntelProcessor createProcessor() ;
}

public class SmartPhoneFactory implements AbstractProcessorFactory
{
public InterlProcessor createProcessor(){
     SmartPhone phone = new SmartPhone() ;
     phone.setProcessorName() ;
     phone.implementProcessor() ;
    return phone ;
}
}

public class LaptopFactory implements AbstractProcessorFactory
{

public InterlProcessor createProcessor(){
     Laptop laptop = new Laptop() ;
     laptop.setProcessorName() ;
     laptop.implementProcessor() ;
    return laptop;
}
}

public class ProcessorBuilder() {
 public void buildProcessor(AbstractProcessorFactory factory ) {
    IntelProcessor = factory.createProcessor() ;
 }
}

public static void main(String processarName[]) {
      AbstractProcessorFactory apf = null ;
ProcessorBuilder builder = new ProcessorBuilder() ;
if (processorName[0].equals("SmartPhone")){
      apf = new SmartPhoneFactory() ;

}else if(processorName[0].equals("Laptop")){
     apf = new LaptopFactory() ;
}
builder.builProcessor(apf) ;
}

No comments:

Generate Insert Sql from Select Statement

SELECT 'INSERT INTO ReferenceTable (ID, Name) VALUES (' +        CAST(ID AS NVARCHAR) + ', ''' + Name + ''...