You have some underlying algorithms and from client you want to use interchangibly.

class IStrategy {
public:
    virtual ~ IStrategy() {

    }

    virtual void process() = 0;
};

class StrategyA : public IStrategy {
    public:
        virtual void process() {
            cout <<" process using Stategy A " <<endl;
        }
};

class StrategyB : public IStrategy {
    public:
        virtual void process() {
            cout <<" process using Stategy B " <<endl;
        }
};

class User {
    private:
        unique_ptr<IStrategy> mStrategy;
    public:
        User(unique_ptr<IStrategy> strategy) : mStrategy(std::move(strategy)) {

        }
        void process() {
            mStrategy->process();
        }
};

int main() {
    User a(make_unique<StrategyA>());
    a.process();

    User b (make_unique<StrategyB>());
    b.process();
}

Follow more posts @ https://jdecodes.wordpress.com

My all design pattern articles :

It’s Jdecoder

I am trying to decode the concepts into simple words and documenting items i know or currently learning.

Let’s connect

Design a site like this with WordPress.com
Get started