Mid From PDF GoF Patterns Gang of Four Patterns

Concrete Command (AddTextCommand):?

  • The AddTextCommand is a concrete implementation of the ICommand
interface. It encapsulates the request to add text to the document.
  • The Execute() method adds the specified text to the document, and the

Undo() method removes that text.

public class AddTextCommand : ICommand
{
private readonly Document _document;
private readonly string _text;
public AddTextCommand(Document document, string text)
{
_document = document;
_text = text;
}
public void Execute() => _document.AddText(_text);
public void Undo() => _document.RemoveText(_text);
}

More from Design Patterns in C#

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details