package demo2;
/**
*
* @author saiweisiaa
*简单工厂模式的学习
*/
class productA implements product{
public void getName(){
System.out.println("hello,I am A product");
}
}
class productB implements product{
public void getName(){
System.out.println("Hello,I am B product");
}
}
public class productCreator {
public product createProducta(String type){
if(type.equals("A")){
return new productA();
}else if(type.equals("B")){
return new productB();
}else{
return null;
}
}
public static void main(String args[]){
productCreator pcCreator=new productCreator();
pcCreator.createProducta("A").getName();
}
}