Categories
Technology Reviews

C++ factory method pattern and data abstraction

Code: //graphic-api.hpp class GraphicApi { public: enum class Type { //OPENGL, //DIRECTX, VULKAN }; virtual void render() = 0; virtual ~GraphicApi() {}; static std::unique_ptr<GraphicApi> make(const Window& window, Type type); }; //graphic-api.cpp //need to include headers for derived classes std::unique_ptr<GraphicApi> GraphicApi::make(const Window& window, GraphicApi::Type type) { switch (type) { case GraphicApi::Type::VULKAN: return std::make_unique<VulkanApi>(window); default: assert(0 && […]