State Pattern in TypeScript

Not to be confused with object state, i.e., one of more attributes that can be copied as a snapshot, the State Pattern is more concerned about changing the handle of an object’s method dynamically. This makes an object itself more dynamic and may reduce the need of many conditional statements.

Instead of storing a value in an attribute, and then using conditional statements within an objects’ method to produce different output, a subclass is assigned as a handle instead. The object/context doesn’t need to know about the inner working of the assigned subclass that the task was…

--

--

--

A Design Pattern is a description or template that can be repeatedly applied to a commonly recurring problem in software design. A familiarity of Design Patterns is very useful when planning, discussing, managing and documenting your applications from now on and into the future.

Recommended from Medium

7 type tricks in 7 minutes

Node.js Promise Catch

Sending Push Notifications over AGC Cloud Functions

Learn JavaScript ES6 and Beyond: Mutating Const

Angular: NGRX a clean and clear introduction

My first React project (part I)

Adding Animation to React Components with react-motion

Unleashing the power of React Table Part 2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sean Bradley

Sean Bradley

Developer of real time, low latency, high availability, asynchronous, multi threaded, remotely managed, fully automated and monitored solutions.

More from Medium

Strategy Pattern in TypeScript

In-Depth Look at TypeScript Generics: Part 2 — Advanced Inference

Fun With TypeScript Template Literal Types

TypeScript Type Gymnastics: Array lengths implement numerical operations