Strategy Pattern in TypeScript

The Strategy Pattern is similar to the State Pattern, except that the client passes in the algorithm that the context should run.

The algorithm should be contained within a class that implements the particular strategies interface.

An application that sorts data is a good example of where you can incorporate the Strategy pattern.

There are many methods of sorting a set of data. E.g., Quicksort, Mergesort, Introsort, Heapsort, Bubblesort. See https://en.wikipedia.org/wiki/Sorting_algorithm for more examples.

--

--

--

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

Frequency

Display Role Hierarchy using Lightning Tree

Basics, Basics, Basics

How to: generate 2D matrix from an Array of random values with Javascript

‘ is not recognized as an internal or external command, operable program or batch file.

Good Practices Node.js with Typescript.

Custom Hooks in React

🌐Our new website is live! (REAPIt.io)

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

State Pattern in TypeScript

How to deal with inferred TypeScript types and stop using any

Extending TypeScript Generics for Additional Type Safety

Advanced TypeScript: Type-Level Nested Object Paths

Example of nested object paths in typescript