Family and vehicles example using the strategy pattern I have studied the strategy pattern and understood it w.r.t the example given in the PDF that I referred. I wanted to make sure that my understanding is correct, so I have written a simple program in C++ and designed the strategy pattern using the family and vehicles as the subject. Please provide corrections/suggestions for the program.

#include &lt;iostream&gt;

class Vehicle
{
public:
    virtual void useVehicle() = 0;
};

class FordFigo : public Vehicle
{
public:
    void useVehicle()
    {
        std::cout &lt;&lt; "Driving FordFigo" &lt;&lt; std::endl;
    }
};

class TataNano : public Vehicle
{
public:
    void useVehicle()
    {
        std::cout &lt;&lt; "Driving TataNano" &lt;&lt; std::endl;
    }
};

class BlackPulsar : public Vehicle
{
public:
    void useVehicle()
    {
        std::cout &lt;&lt; "Riding BlackPulsar" &lt;&lt; std::endl;
    }
};

class HondaActiva : public Vehicle
{
public:
    void useVehicle()
    {
        std::cout &lt;&lt; "Riding HondaActiva" &lt;&lt; std::endl;
    }
};

class Family
{
public:
    Vehicle *myVehicle;
    virtual void display() = 0;
    void setVehicle(Vehicle *v)
    {
        myVehicle = v;
    }
    void driveVehicle()
    {
        myVehicle-&gt;useVehicle();
    }
};

class Father : public Family
{
public:
    virtual void display()
    {
        std::cout &lt;&lt; "I am Father" &lt;&lt; std::endl;
    }
};

class Mother : public Family
{
public:
    virtual void display()
    {
        std::cout &lt;&lt; "I am Mother" &lt;&lt; std::endl;
    }
};


class Son : public Family
{
public:
    virtual void display()
    {
        std::cout &lt;&lt; "I am Son" &lt;&lt; std::endl;
    }
};


class Daughter : public Family
{
public:
    virtual void display()
    {
        std::cout &lt;&lt; "I am Daughter" &lt;&lt; std::endl;
    }
};

int main()
{
    Family *fam = new Father();
    fam-&gt;display();
    fam-&gt;setVehicle(new FordFigo());
    fam-&gt;driveVehicle();

    fam = new Daughter();
    fam-&gt;display();
    fam-&gt;setVehicle(new HondaActiva());
    fam-&gt;driveVehicle();
    return 0;
}
In "modern C++" it is unusual to see (and use) RAW pointers.

class Family
{
public:
    Vehicle *myVehicle;


Here you have a pointer to a vehicle. But there is no indication of who owns the vehicle. Does the family member own the vehicle or is a shared resource? Can a family member have no vehicle in which case what is the appropriate response to driveVehicle()? Maybe with no vehicle they default to walking?

Anyway. Don't use pointers. In terms of memory management they do not indicate who the owner of the pointed at object is; Note: it is the responsibility of the owner to delete the object. If you don't know who should delete it you have memory leaks (and there is a lot in your code).

Also by default pointers are not set to NULL. So if you do not explicitly initialize them in a constructor you have a random value (so initialize them).

What happens if myVehicle is NULL here?

void driveVehicle()
{
    myVehicle-&gt;useVehicle();
}


You should mark virtual implementations as override

void display() override  // indicates this is the implementation
                         // of a virtual function.
{
    std::cout &lt;&lt; "I am Daughter" &lt;&lt; std::endl;
}


Never use dynamic memory memory management when local variables will do.

Family *fam = new Father();

// This should be:

Father father;