factory.java

来自「JAVA编程百例书中各章节的所有例子的源代码,包括套接字编程」· Java 代码 · 共 25 行

JAVA
25
字号
package ch10.section01;

public class Factory {
  public Window CreateWindow(String type) {
    if (type.equals("Big")) {
      return new WindowBig();
    }
    else if (type.equals("Small")) {
      return new WindowSmall();
    }
    else {
      return new WindowBig();
    }
  }

  public static void main(String[] args) {
    Factory myFactory = new Factory();
    Window myBigWindow = myFactory.CreateWindow("Big");
    myBigWindow.func();

    Window mySmallWindow = myFactory.CreateWindow("Small");
    mySmallWindow.func();
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?