Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorect implementation UnExecute method in CommandPattern #4

Open
ghost opened this issue Mar 19, 2018 · 0 comments
Open

Incorect implementation UnExecute method in CommandPattern #4

ghost opened this issue Mar 19, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Mar 19, 2018

https://github.com/skimedic/presentations/tree/master/Patterns/BehavioralPatterns/Command/AddNumbersCommand.cs and AddTextCommand.cs

When we use two or more Command object, UnExecute method work incorrect. For example when we add text, number and text and we want to undo last change for numberCommand we remove string (which have length of added number) from global StringBuilder object

Look at this code

            var text1 = "abc";
            var text2 = "defgh";
            var numb1 = "1234";

            var controller = new Controller();

            var addNumbCommandReference = controller.AddCommand(new AddNumbersCommand());
            var addTextCommandReference = controller.AddCommand(new AddTextCommand());           

            controller.GetCommandAt(addTextCommandReference).Execute(text1);
            controller.GetCommandAt(addNumbCommandReference).Execute(numb1);
            controller.GetCommandAt(addTextCommandReference).Execute(text2);
            
            controller.GetCommandAt(addNumbCommandReference).UnExecute();

            //Output
            //abc1234d
            //Expected:
            //abcdefgh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants