zoukankan      html  css  js  c++  java
  • 设计模式之GOF23工厂模式02

    抽象工厂模式

    不能添加单个产品,产品族

    public interface Seat {
      void anmo();
    }
    class GoodSeat implements Seat {
     @Override
     public void anmo() {
       System.out.println("可以按摩");  
     }
    }
    class LowSeat implements Seat {
     @Override
     public void anmo() {
       System.out.println("不可以按摩");  
     }
    }

    public interface Tyre {
      void piaoyi();
    }
    class GoodTyre implements Tyre{
     @Override
     public void piaoyi() {
      System.out.println("可以漂移");
     }
    }
    class LowTyre implements Tyre{
     @Override
     public void piaoyi() {
      System.out.println("不可以漂移");
     }
    }

    public interface Engine {
      void run();
      void start();
    }
    class GoodEngine implements Engine {
     @Override
     public void run() {
      System.out.println("跑的快");
     }
     @Override
     public void start() {
        System.out.println("启动的快");
     }
    }
    class LowEngine implements Engine {
     @Override
     public void run() {
      System.out.println("跑的慢");
     }
     @Override
     public void start() {
        System.out.println("启动的慢");
     }
    }

    public interface CarFactory {
      Engine creatEngine();
      Seat creatSeat();
      Tyre creatTyre();
    }

    public class GoodCarFactory implements CarFactory{
     @Override
     public Engine creatEngine() {
      return new GoodEngine();
     }
     @Override
     public Seat creatSeat() {
      return new GoodSeat();
     }
     @Override
     public Tyre creatTyre() {
      return new GoodTyre();
     }
    }

    public class LowCarFactory implements CarFactory{
     @Override
     public Engine creatEngine() {
      return new LowEngine();
     }
     @Override
     public Seat creatSeat() {
      return new LowSeat();
     }
     @Override
     public Tyre creatTyre() {
      return new LowTyre();
     }
    }

    public class Client {
     public static void main(String[] args) {
     }
    }
  • 相关阅读:
    nginx反向代理编译异常
    TCP/ip协议栈之内核调优
    Tcp之异常
    Codeforces Round #584
    Codeforces Round #588 (Div. 2)
    Codeforces Round #587 (Div. 3) F
    P4587 [FJOI2016]神秘数 主席树
    P4559 [JSOI2018]列队 主席树
    P4098 [HEOI2013]ALO 可持久化01trie
    4771: 七彩树 主席树
  • 原文地址:https://www.cnblogs.com/code-fun/p/11311982.html
Copyright © 2011-2022 走看看