zoukankan      html  css  js  c++  java
  • 设计模式-抽象工厂模式

    抽象工厂模式,定义工厂接口,生产某一种类型的配件全部由某一家工厂所提供,解决不同工厂的兼容性问题。

    /**
     * 抽象工厂模式
     */
    public class AbstratFactoryMethod {
        public static void main(String[] args) {
         Application application = new ConcreteProductA();
    // Application application = new ConcreteProductA1();
    Product product = application.getObject();
    product.method1();
    } } //数据库连接接口,抽象工厂 interface IDatabaseUtils { IConnection getConnection(); ICommand getCommand(); } //连接接口 interface IConnection { void connect(); } //指令接口 interface ICommand { void command(); } //实现类1 class MysqlConnection implements IConnection { @Override public void connect() { System.out.println("mysql connect"); } } //实现类2 class OracleConnection implements IConnection { @Override public void connect() { System.out.println("Oracle connect"); } } //实现类1 class MysqlCommand implements ICommand { @Override public void command() { System.out.println("mysql command"); } } //实现类2 class OracleCommand implements ICommand { @Override public void command() { System.out.println("Oracle command"); } } //抽象工厂实现1 class MysqlDataBaseUtils implements IDatabaseUtils { @Override public IConnection getConnection() { return new MysqlConnection(); } @Override public ICommand getCommand() { return new MysqlCommand(); } } //抽象工厂实现1 class OracleDataBaseUtils implements IDatabaseUtils { @Override public IConnection getConnection() { return new OracleConnection(); } @Override public ICommand getCommand() { return new OracleCommand(); } }

      

  • 相关阅读:
    window下安装两个mysql服务
    Linux 下 FastDFS v5.08 分布式文件系统的安装
    linux 下 php 安装 ZeroMQ 扩展
    win 下 nginx 与 php的配置
    Navicat Premium11连接Oracle出现ORA-28547:connection to server failed
    dedecms的自定义模块
    php 的多进程实践
    php多进程 防止出现僵尸进程
    php Pthread 多线程 (一) 基本介绍
    php 使用PHPExcel 导出数据为Excel
  • 原文地址:https://www.cnblogs.com/chenfx/p/14779194.html
Copyright © 2011-2022 走看看