Click here to Skip to main content
15,884,298 members
Articles / Programming Languages / C#

The State Design Pattern vs. State Machine

Rate me:
Please Sign up or sign in to vote.
4.62/5 (36 votes)
8 Mar 2013CPOL14 min read 283.5K   75  
How to use the State Design Pattern when compared to State Machines, Switch statements, or If statements.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain
{
    public abstract class ModeState : DomainObject
    {
        protected Device _device;

        public Device Device
        {
            get { return _device; }
            set { _device = value; }
        }

        public abstract void SetModeToPowerUp();
        public abstract void SetModeToIdle();
        public abstract void SetModeToBusy();
        public abstract void SetModeToPowerDown();
    }
}

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
United States United States
Thomas Jaeger is a Solutions Architect and an industry expert for over 24 years in 10 different industries when it comes to software development in general, cloud-based computing, and iOS development. He is a passionate, fanatic, software designer and creator. He lives against the status quo because, in his opinion, creative and innovative solutions are not created following a linear approach but come, in part, from broad experiences in ones life and from an innovative mind.

Comments and Discussions