commandfactory.java
来自「Java编写个人日程管理工具, 具有添加编辑日程和自动适应功能, 程序包含完整的」· Java 代码 · 共 71 行
JAVA
71 行
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package ui;import exception.NoExistsCommandException;/** * 用于生产命令对象的工厂 * @author zouhao */public class CommandFactory { private static CommandFactory instance = null; /** * 此方法是为了实现CommandFactory的Singleton * @return */ public static synchronized CommandFactory getInstance() { if (instance==null) { instance=new CommandFactory(); } return instance; } /** * 实现命令选择并动态生成相应对象 * @param which 选择输入 * @return 生成的命令对象 */public static Command factory(String which) { try{ if (which.equalsIgnoreCase("register")) { return new RegisterCommand(); } else if (which.equalsIgnoreCase("add")) { return new AddCommand(); } else if (which.equalsIgnoreCase("delete")) { return new DeleteCommand(); } else if (which.equalsIgnoreCase("query")) { return new QueryCommand(); } else if (which.equalsIgnoreCase("clear")) { return new ClearCommand(); } else if (which.equalsIgnoreCase("batch")) { return new BatchCommand(); } else if (which.equalsIgnoreCase("help")) { return new HelpCommand(); } else { throw new NoExistsCommandException(); } } catch(NoExistsCommandException e){} return null; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?