小编Ult*_*nia的帖子

在ArrayLists中使用Command模式进行撤消和重做

所以我有一个程序,你可以登录并添加/删除friendsarraylist的朋友.此外,我可以喜欢某件事,那件事会存入likesarraylist.我被要求为我做的任何动作做出撤销和重做选项.

所以我想把苹果添加为朋友.之后,当我选择撤消选项时,我可以撤消该操作,因此苹果不会成为我的朋友.Command Pattern当输入是我输入存储到friendsarraylist中的任何名称或单词时,我如何处理此问题?

我做了一些研究,发现使用命令模式可能是我最好的选择,因为这必须在我已经拥有的Facebook类下完成.我假设我将不得不使用两个不同的堆栈,但我在主题中有点迷失.

我决定添加我所拥有的部分内容,这样我就可以获得更多帮助,了解我需要做什么以及我的程序做了什么.

在驱动程序中

Facebook facebook1 = new Facebook();

            if (userInput == 6) 
            {
                System.out.println("Login");
                String operand1 = getOperand("What is the Username? ");
                String operand2 = getOperand("What is the Password? ");
                System.out.println("Enter a friend to be added. ");
                String operand3 = getOperand("What is the Username? ");
                facebook1.friend(operand3);
            }

            if (userInput == 7) 
            {
                System.out.println("Login");
                String operand1 = getOperand("What is the Username? ");
                String operand2 = getOperand("What …
Run Code Online (Sandbox Code Playgroud)

java arraylist command-pattern

7
推荐指数
1
解决办法
6044
查看次数

标签 统计

arraylist ×1

command-pattern ×1

java ×1