Strategy Design Pattern - What it is ? Why it is needed ? - C#

Posted on 2011-10-24
Last Modified: 2013-11-11

Can you please explain to me in simple words:

What is Strategy Design Pattern ?
Why it is needed ?

Please do NOT provide me links / articles.

Question by:milani_lucie
    LVL 37

    Expert Comment

    A strategy design pattern is a design pattern where it is not known ahead of time what algorithms will need to be run on whatever data may be coming into the system.
    All the algorithms that may need to be used are compiled into the program and then the characteristics of the data or the users choices determine which algorithm should run.
    LVL 2

    Accepted Solution

    Let's explain it the easy way :

    You have a class Car() with a method run() so you use it this way in a pseudo language :

    mycar = new Car()

    Now, you may want to change the run() behavior on the fly, while the program is executing. E.G : to simulate a motor failure or the use of a "boost" button in a video game.

    There are several ways to do that : using conditional statements and a flag variable is one of them. The strategy pattern is another, that delegate the behaviour of the run() method to a subclass :

    Class Car()
        this.motor = new Motor(this)

        // passing "this" is important for the motor so it knows what it is running

        method run()

        method changeMotor(motor)


    If you want to change the car behavior, you can just change the motor (easier in a program that in the real life, right ;-) ?)

    It's very useful if you have a lot of complex states : you can change and maintain them much more easily.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Before You Read The Article Please make sure you understand these two concepts: Variable Scope ( and Property Visibility (  And to …
    "Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video discusses moving either the default database or any database to a new volume.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now