So recently I started learning some design patterns. I stuck at Dependency Injection. After few hours of trying to understand it I wrote some code. Could you tell me if this code represents pattern Dependency Injection? If not please let me now what I have to change there.
#include <iostream>
using namespace std;
class ICar
{
public:
virtual string drive () = 0;
};
class Audi : public ICar
{
public:
string drive () override
{
return "I drive Audi";
}
};
class VW : public ICar
{
public:
string drive () override
{
return "I drive VW";
}
};
void displayInfo (ICar& icar)
{
cout << icar.drive () << endl;
}
int main ()
{
VW v1;
displayInfo (v1);
}
Thanks for help :)
Aucun commentaire:
Enregistrer un commentaire