using System.Collections;
using System.Collections.Generic;
public interface ICommand
public interface IUndoableCommand: ICommand
public string Content {get; set;}
Content = "<b>" + Content + "</b>";
public class BoldCommand: IUndoableCommand
private Document document;
private string prevContent;
public BoldCommand(Document document, History history)
this.prevContent = document.Content;
document.Content = this.prevContent;
public class UndoCommand: ICommand
public UndoCommand(History history)
var command = history.Pop();
private Stack<IUndoableCommand> stack = new Stack<IUndoableCommand>();
public void Push(IUndoableCommand command)
public IUndoableCommand Pop()
public static void Main()
var history = new History();
var document = new Document();
document.Content = "Hello World";
Console.WriteLine(document.Content);
var command = new BoldCommand(document, history);
Console.WriteLine(document.Content);
var undoCommand = new UndoCommand(history);
Console.WriteLine(document.Content);