interface Phone{
public void creatPhone();
}
class Apple implements Phone{
public void creatPhone(){
System.out.println("I got one IPhone");
}
}
class HuaWei implements Phone{
public void creatPhone(){
System.out.println("I got one HuaWeiMate7");
}
}
class Factory{
public static Phone getInstance(String phoneName){
if(phoneName.equals("Apple")){
return new Apple();
}else if(phoneName.equals("HuaWei")){
return new HuaWei();
}else{
return null;
}
}
}
public class TestDemo{
public static void main(String args[]){
Phone newPhone = Factory.getInstance("HuaWei");
newPhone.creatPhone();
}
}
09-01
09-01
01-20