Click here to Skip to main content
15,885,216 members
Articles / Programming Languages / C#

A Simple State Machine

Rate me:
Please Sign up or sign in to vote.
4.67/5 (28 votes)
23 Jan 2014CPOL3 min read 121.7K   4.6K   117  
Create loose coupled States using a Finite State Automation (FSM) model.
using System;

namespace AbstractFSM
{
    public class StateEventArgs : EventArgs
    {
        public StateEventArgs(int id)
        {
            m_id = id;
        }
        private int m_id;
        public int Id
        {
            get { return m_id; }
        }
    }

    public class State
    {
        private String m_sState = null;
        public State(string sState)
        {
            m_sState = sState; 
        }
        protected virtual void ChangeState(object sender, StateEventArgs eventArgs) {}

        public override string ToString()
        {
            return m_sState;
        }
    }
}

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
Software Developer (Senior)
Canada Canada
Has been engaging in software development for over 15 years. Has deliberately chosen this path and has no compunction about it at all. Has a nasty habit of sharing his 'out-of-office' code hoping to get some positive feedback. Smile | :)

Comments and Discussions