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() ;
}
{
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;
}
}
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:
Post a Comment