#include <iostream>
#include <memory>
class Car {
public:
virtual ~Car() = default;
virtual std::string type() const = 0;
};
class SportsCar : public Car {
std::string type() const override { return "SportsCar"; }
class FamilyCar : public Car {
std::string type() const override { return "FamilyCar"; }
class Truck {
virtual ~Truck() = default;
class SportsTruck : public Truck {
std::string type() const override { return "SportsTruck"; }
class FamilyTruck : public Truck {
std::string type() const override { return "FamilyTruck"; }
class VehicleFactory {
virtual Car *createCar() const = 0;
virtual Truck *createTruck() const = 0;
class SportsVehicleFactory : public VehicleFactory {
Car *createCar() const override { return new SportsCar; }
Truck *createTruck() const override { return new SportsTruck; }
class FamilyVehicleFactory : public VehicleFactory {
Car *createCar() const override { return new FamilyCar; }
Truck *createTruck() const override { return new FamilyTruck; }
int main(int argc, char *argv[]) {
std::cout << "AbstractFactory" << std::endl;
auto sportsTruck =
std::unique_ptr<Truck>(SportsVehicleFactory().createTruck());
auto familyCar = std::unique_ptr<Car>(FamilyVehicleFactory().createCar());
std::cout << "I am a " << sportsTruck->type() << std::endl;
std::cout << "I am a " << familyCar->type() << std::endl;
return EXIT_SUCCESS;
}