Click here to Skip to main content
15,895,011 members
Articles / Programming Languages / C#

Practical approach to Memento design pattern

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
28 Dec 2012CPOL4 min read 32.9K   354   11  
This article explains the implementation of undo/redo using a Memento Pattern.

namespace MementoPattern
{
    /// <summary>
    /// Memento to get/set the state of an Employee
    /// </summary>
    public class EmployeeMemento
    {
        private string _firstName;
        private string _lastName;
        private uint _id;

        public EmployeeMemento(Employee emp)
        {
            _firstName = emp.FirstName;
            _lastName = emp.LastName;
            _id = emp.Id;
        }

        public EmployeeMemento(string firstName, string lastName, uint id)
        {
            _firstName = firstName;
            _lastName = lastName;
            _id = id;
        }

        public string FirstName
        {
            get
            {
                return _firstName;
            }
            set
            {
                _firstName = value;
            }
        }

        public string LastName
        {
            get
            {
                return _lastName;
            }
            set
            {
                _lastName = value;
            }
        }

        public uint Id
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Harman International
India India
I am a Microsoft .Net developer having experience in developing enterprise applications using technologies such as WPF, Winform. Always look towards making the life simple by developing GUI based applications.

Comments and Discussions