package model; import java.util.ArrayList; import java.util.List; /** * 单例模式:全局唯一记录用户所有输入命令 */ public class HistoryCommand { // 保存所有命令 private final List commandList; // 单例实例 private static HistoryCommand instance; // 私有构造 private HistoryCommand() { commandList = new ArrayList<>(); } // 获取唯一实例 public static HistoryCommand getInstance() { if (instance == null) { instance = new HistoryCommand(); } return instance; } // 添加命令 public void addCommand(String command) { commandList.add(command); } // 获取所有历史命令 public List getAllCommand() { return commandList; } }