静止的流水的学习日志
静止的流水
全部博文(210)
Windows(1)
Linux(31)
2011年(34)
2010年(121)
2009年(37)
2008年(18)
cynthia
wojiuzhu
jd_lzh
鄙人姓王
Jack_Tan
fanbiubi
猜我咯
aaccp1
chrisy52
分类: Java
2011-03-16 16:40:13
package com.utstar.pattern.abstractfactory;public interface Cpu { public abstract void calculate();}
package com.utstar.pattern.abstractfactory;public class IntelCpu implements Cpu{ public int pins; public IntelCpu(int p){ this.pins = p; } public void calculate(){ System.out.println("Intel Cpu."); }}
package com.utstar.pattern.abstractfactory;public class AmdCpu implements Cpu{ public int pins; public AmdCpu(int p){ this.pins = p; } public void calculate(){ System.out.println("AmdCpu."); }}
package com.utstar.pattern.abstractfactory;public interface MainBoard { public abstract void install();}
package com.utstar.pattern.abstractfactory;public class GigaMainBoard implements MainBoard{ public int pins; public GigaMainBoard(int p){ this.pins = p; } public void install(){ System.out.println("技嘉主板"); }}
package com.utstar.pattern.abstractfactory;public class MsiMainBoard implements MainBoard{ public int pins; public MsiMainBoard(int p){ this.pins = p; } public void install(){ System.out.println("微星主板"); }}
package com.utstar.pattern.abstractfactory;public interface Factory { public abstract Cpu createCpu(); public abstract MainBoard createMainBoard();}
package com.utstar.pattern.abstractfactory;public class IntelFactory implements Factory{ public Cpu createCpu(){ return new AmdCpu(936); } public MainBoard createMainBoard(){ return new GigaMainBoard(936); }}
package com.utstar.pattern.abstractfactory;public class AmdFactory implements Factory{ public Cpu createCpu(){ return new AmdCpu(1189); } public MainBoard createMainBoard(){ return new GigaMainBoard(1189); }}
package com.utstar.pattern.abstractfactory;public class TestAbstractFactory{ public static void main(String args[]){ Cpu cpu1 = new IntelFactory().createCpu(); MainBoard board1 = new IntelFactory().createMainBoard(); cpu1.calculate(); board1.install(); }}
上一篇:Java设计模式-简单工厂模式(七)
下一篇:java设计模式-桥接模式(八)
登录 注册