skip to Main Content

Welcome

Say hello to the toggle bar. This is an optional section you can use to display any content you'd like. Simply select a page from the theme panel and the content of the page will display here. You can even use the drag and drop builder to create this! This is a perfect place for your company mission statement, alerts, notices or anything else.

Get In Touch

Email: support@total.com
Phone: 1-800-Total-Theme
Address: Las Vegas, Nevada

Our Location

togglebar-map

State Pattern

Post Series: Behavioral Design Pattern

This pattern is used when there is one to many relationship between objects such as if one object is modified, its dependent objects are to be notified automatically.This pattern is used to alter the behavior of an object when it’s internal state changes. In this pattern, an object is created which represent various states and a context object whose behavior varies as it’s state object changes.

State Design Pattern C#

  • Context: This is a class that holds a concrete state object that provides the behavior according to its current state. This is used by the clients.
  • State: This is an interface that is used by the Context object to access the changeable functionality.
  • ConcreteStateA/B: These are classes that implements State interface and provide the real functionality that will be used by the Context object. Each concrete state class provides behavior that is applicable to a single state of the Context object.

Implement

Example

Real Life Example of State Design Pattern C#

When to use it?

  1. The behavior of an object is changed based on its state.
  2. Preserve flexibility in assigning requests to handlers.
  3. An object is becoming complex, with many conditional behaviors.

Resource

http://www.dotnettricks.com/learn/designpatterns/state-design-pattern-c-sharp

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top