简单工厂模式demo
1. 简单工厂模式
domain的接口
public interface Color{ public void display(); }
red
public Class Red implements Color{ @Override public void display(){ "我是红色"; } }
blue
public Class Blue implements Color{ @Override public void display(){ "我是蓝色"; } }
颜色工厂
public class SampleFactory { public static Color makeColor(String type){ if("Red".equals(type)){ Color color= new Red(); return color; }else if("Blue".equals(type)){ Color color= new Red(); return color; }else{ return null; } } }