Problem
Sample of builder pattern
Solution
#include <iostream>
#include <memory>
using namespace std;
class Burn
{
public:
virtual void Authoring() = 0;
virtual void Burning() = 0;
};
class CDBurn : public Burn
{
public:
void Authoring() override;
void Burning() override;
};
void CDBurn::Authoring()
{
cout << "CD Authoring" << endl;
}
void CDBurn::Burning()
{
cout << "CD Burning" << endl;
}
class DVDBurn : public Burn
{
public:
void Authoring() override;
void Burning() override;
};
void DVDBurn::Authoring()
{
cout << "DVD Authoring" << endl;
}
void DVDBurn::Burning()
{
cout << "DVD Burning" << endl;
}
class BlurayBurn : public Burn
{
public:
void Authoring() override;
void Burning() override;
};
void BlurayBurn::Authoring()
{
cout << "Blu-ray Authoring" << endl;
}
void BlurayBurn::Burning()
{
cout << "Blu-ray Burning" << endl;
}
class BurnBuild
{
public:
BurnBuild(Burn* _burn) : burn(_burn) {};
void Burning();
private:
Burn* burn;
};
void BurnBuild::Burning()
{
burn->Authoring();
burn->Burning();
}
int main()
{
Burn* burnApp[3]{ new CDBurn(), new DVDBurn(), new BlurayBurn() };
for (auto burn : burnApp) {
BurnBuild bb(burn);
bb.Burning();
}
return 0;
}
Output
CD Authoring
CD Burning
DVD Authoring
DVD Burning
Blu-ray Authoring
Blu-ray Burning
Press any key to continue . . .