helloworld:design_pattern:fabrique_abstraite:cpp
- main.cpp
#include <iostream> class ICar { public: virtual void DriveCar() = 0; }; class Car : public ICar { void DriveCar() override { std::cout << "Car has been driven!"; } }; class ProxyCar : public ICar { private: ICar* realCar = new Car(); int _driver_age; public: ProxyCar (int driver_age) : _driver_age(driver_age) {} void DriveCar() { if (_driver_age > 16) realCar->DriveCar(); else std::cout << "Sorry, the driver is too young to drive."; } }; //How to use above Proxy class? int main() { ICar* car = new ProxyCar(16); car->DriveCar(); delete car; car = new ProxyCar(25); car->DriveCar(); delete car; return 0; }
helloworld/design_pattern/fabrique_abstraite/cpp.txt · Dernière modification : 2020/05/11 01:18 de root