{{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:

Could not find method signingConfigs() for arguments

Could not find method signingConfigs() for arguments [build_5dw7nwfc8ibd8sagvx4p79x1u$_run_closure5@13e86039] on root project 'android&#...