Java简单工厂模式
package pattern.factory;public interface HuMan {public void eat();public void walk();}?
package pattern.factory;public class Chinese implements HuMan {public void eat() {System.out.println("中国人喜欢吃大米!");}public void walk() {System.out.println("中国人喜欢骑自行车!");}}?
package pattern.factory;public class Usa implements HuMan {public void eat() {System.out.println("美国人喜欢吃面包!");}public void walk() {System.out.println("美国人喜欢开汽车!");}}?
package pattern.factory;public class Factory {private HuMan huMan = null;public Factory(HuMan huMan) {this.huMan = huMan;}public HuMan getInstance() {return huMan;}}?
package pattern.factory;public class TestFactory {/** * @param args */public static void main(String[] args) {HuMan usa=new Factory(new Usa()).getInstance();usa.eat();usa.walk();}}?