Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 73509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:12:46+00:00 2026-05-10T20:12:46+00:00

When I first discovered the Strategy pattern, I was amazed of the seemingly endless

  • 0

When I first discovered the Strategy pattern, I was amazed of the seemingly endless possibilities it offered to me and my programs. I could better encapsulate my models’ behaviour and even exchange this behaviour on the fly. But the strategy could also be used to to provide traits and payload to the containing object – data that was declared in a superclass. Life was fine.

class MyMonsterAI   { float const see_radius_; virtual void attack () = 0; /* .. */ }; class ElveAI        { ElveAI() : see_radius_(150.0f) {} /* ... */ }; class CycloneAI     { CycloneAI() : see_radius_(50.0f) {} /* ... */ }; class Monster       { MyMonsterAI* ai_; }; 

And along came the Policy pattern and it would allow me even greater flexibility in supplying parameters to a containing class – whole classes, outfitted however I liked, albeit dynamically exchanging the behaviour… that was not too easy (unless part of the policy was to have a strategy!).

class MyMonsterTrait { typedef typename ElveAI AI; };  template< class MonsterTrait > class Monster : public MonsterTrait::AI {     void idle (void) { attack(); } }; 

Both patterns seem to be very powerful to me and I like to use both, in different circumstances. But I’m not sure if there are particular/typical/more-practical applications for either at some situations.

I am wondering: where do you use strategies and where policies? Where are either better suited?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:12:46+00:00Added an answer on May 10, 2026 at 8:12 pm

    Policies are largely set at compile time, while strategies are set at runtime. Further, policies are generally a C++ concept, and apply only to a minority of other languages(for example D), while strategy pattern is available to many (most?) object oriented languages, and languages that treat functions as first class citizens like python.

    That being said:

    • A policy, being determined at compile time, is generally only useful for special situations where you want different application logic on a per-binary basis. For instance you might develop software that is slightly customized for each customer, whether via a web interface, or by hand, this would be a policy-based pattern.

    • A strategy is determined at runtime, and in fact can be changed on the fly. For instance you might have software which implements a different user interface and logic for the salesforce than for the support group, but they all have to deal with the same customer and licensing info so rather than having two separately maintained apps you simply have one app whose interface changes as needed.

    -Adam

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A few quick searches discovered that I'm obviously not the first person to have
When I discovered MVC (first with ASP.NET MVC), I thought it was the holy
Having recently discovered design patterns, and having acquired the excellent Head First Design Patterns
My first app just went live and I am thrilled. Now I've discovered that
First, let's get the security considerations out of the way. I'm using simple authentication
First off, I am using Windows XP. I have multiple hard drives and it
First off, I understand the reasons why an interface or abstract class (in the
First off if you're unaware, samba or smb == Windows file sharing, \\computer\share etc.
First of all, I know how to build a Java application. But I have
First off, there's a bit of background to this issue available on my blog:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.