Реализации на С++
Factory method
Общая реализация на языке С++
class Car
{
public:
virtual ~Car() = default;
virtual void drive() = 0;
};
class Sedan : public Car
{
public:
Sedan()
{
cout << "Sedan constructor called" << endl;
}
~Sedan() override
{
cout << "Sedan destructor called" << endl;
}
void drive() override
{
cout << "Driving sedan" << endl;
}
};
class SUV : public Car
{
public:
SUV()
{
cout << "Calling the SUV constructor;" << endl;
}
~SUV() override
{
cout << "Calling the SUV destructor;" << endl;
}
void drive() override
{
cout << "Driving SUV;" << endl;
}
};Last updated