Java设计模式:抽像工厂模式
2014-12-14 20:42
267 查看
抽象工厂模式为工厂模式添加了一个抽象层,是创建其它工厂的超级工厂,也称为工厂的工厂。
Abstract Factory class diagram
Abstract Factory class diagram
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package client; interface CPU { void process(); } interface CPUFactory { CPU produceCPU(); } class AMDFactory implements CPUFactory { public CPU produceCPU() { return new AMDCPU(); } } class IntelFactory implements CPUFactory { public CPU produceCPU() { return new IntelCPU(); } } class AMDCPU implements CPU { public void process() { System.out.println("AMD is processing...."); } } class IntelCPU implements CPU { public void process() { System.out.println("Intel is processing..."); } } class Computer { CPU cpu; public Computer(CPUFactory factory) { cpu = factory.produceCPU(); cpu.process(); } } public class Client { public static void main(String[] args) { new Computer(createSpecificFactory()); } public static CPUFactory createSpecificFactory() { int sys = 0; if (sys == 0) return new AMDFactory(); else return new IntelFactory(); } }
相关文章推荐
- Java设计模式圣经连载(02)-工厂方法(Factory Method)模式
- JAVA工厂设计模式(摘自网络)
- java中的设计模式 工厂 和抽象工厂模式 的例子
- JAVA设计模式:简单工厂、工厂方法、抽象工厂之小结与区别
- java设计模式之一 工厂模式
- 设计模式之Factory,Java工厂方法
- Java设计模式之工厂方法模式
- java 简单工厂设计模式
- Java设计模式(2) -- 工厂方法
- Java设计模式之工厂模式
- Java工厂设计模式论文
- Java设计模式之工厂方法模式
- JAVA设计模式学习之----创建模式:工厂模式(工厂方法)
- Java设计模式之二 —— 工厂方法
- JAVA设计模式——简单工厂(Simple Factory)模式
- Java设计模式之工厂模式篇
- 追MM与设计模式的JAVA实现-简单工厂方法
- Java 可复用的面向对象的设计模式之 工厂模式Factory详解 :简单工厂模式 工厂方法模式 抽象工厂模式
- 3.23种设计模式的Java版--Factory Method(工厂方法)
- java设计模式【创建模式】之工厂模式