Возможные реализации для решения конкретных задач на С++

Abstract factory

Абстрактная фабрика с использованием генерации иерархии классов

# pragma region Type List
class NullType {};

template <typename... Types>
struct TypeList;

template <>
struct TypeList<> {};

template <typename H>
struct TypeList<H>
{
	using Head = H;
	using Tail = NullType;
};

template <typename H, typename... Types>
struct TypeList<H, Types...>
{
	using Head = H;
	using Tail = TypeList<Types...>;
};

#pragma endregion
template < typename T>
class Type2Type
{
public:
	using type = T;
};
class BaseGraphics
{
public:	
    virtual ~BaseGraphics() = 0;
};

BaseGraphics::~BaseGraphics() {}


class QtGraphics : public BaseGraphics
{
public:
	QtGraphics() 
	{ 
		cout << "Calling the QtGraphics constructor;" << endl; 
	}
	
	~QtGraphics() override 
	{ 
		cout << "Calling the QtGraphics destructor;" << endl; 
	}
};
# include <iostream>
# include <memory>

using namespace std;

int main()
{
	shared_ptr<AbstractGrFactory> gr = make_shared<QtGrFactory>();

	unique_ptr<User> us = make_unique<User>();

	us->use(gr);
}

Last updated

Was this helpful?