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

  • Home
  • SEARCH
  • 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 3489580
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:24:43+00:00 2026-05-18T11:24:43+00:00

I’m in a class where we just learned about these design patterns. However I

  • 0

I’m in a class where we just learned about these design patterns. However I couldn’t see any difference between them. They sound just like the same, creating concrete classes over the abstract one. Could somebody help me kill this doubt? thanks (:

  • 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. Editorial Team
    Editorial Team
    2026-05-18T11:24:43+00:00Added an answer on May 18, 2026 at 11:24 am

    Both the visitor, the strategy, and the template pattern encompass the application of an algorithm. The biggest difference is in how they are evoked and how they are used in practice. While it may seem like they have the same use case, look at the construction of the objects to see the difference.

    The strategy pattern is often used when we don’t have the ability to pass around functions as a first class object. It expects a very specific argument list and only that argument list in its call pattern. For instance:

    struct MyStrat{
        void operator()(const Foo &_input){
            _input.up( 2 );
        }
    };
    
    std::for_each( myFooList.begin(), myFooList.end(), MyStrat() );
    

    which is then applied to a list of objects of type “Foo.” We really have no other way of applying it to any other object.

    The visitor pattern on the other hand is used when we want to apply an algorithm to a bunch of objects that might not share the same signature nor have the same member functions. We say visitor pattern because it’s often used when traversing a tree or another collection of “unrelated” objects (unrelated in an inheritance sense.)

    struct MyVisitor{
        void visit(const Foo &_input){
             _input.up( 2 );
        }
        void visit(const Bar &_input){
             _input.raiseUp( 2 );
        }
        void visit(const Baz &_input){
             _input.setUp( 2 );
        }
     };
    

    Here, the idea is that we’d like to “up” all these objects. They all don’t share the same member function signature but all are conceptually related. Hence, we can “visit” each of these classes but expect the algorithm to perform the same type of task.

    By using a visitor pattern we avoid the need to wrap each class in a proxy pattern. Hence, for N classes we’d like to apply this algorithm to we don’t need to make N proxy classes. We only need to add N methods to a visitor class.

    The template method is quite different from either the visitor and the strategy pattern. With the template what you’re trying to do is enforce the same type of algorithm but on different subclasses within a hierarchy. For instance:

    class Duck{
    public:
        int count() =0;
        void makeNoise(int times) =0;
        void quack(){ makeNoise( count() ); }//the template pattern is here
    };
    
    class Mallard : public Duck{
    public:
        int count(){ return 4; }
        void makeNoise( cout << "quack" << endl; }
    };
    
    class Daffy{
    public:
        int count(){ return 1; }
        void makeNoise( cout << "Why I ought to..." << endl; }
    };
    

    So the result of the algorithm varies within the heirarchy.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.