Compare commits
No commits in common. "lesson_4_extended" and "master" have entirely different histories.
lesson_4_e
...
master
|
@ -1,7 +0,0 @@
|
|||
Паттерн "Абстрактная Фабрика" предоставляет интерфейс для семейств взаимосвязанных объектов без указания их конкретных классов.
|
||||
|
||||
Все фабричные паттерны обеспечивают слабую связанность за счет сокращения зависимости приложения от конкретных классов.
|
||||
Все фабрики инкапсулируют создание объектов. Абстрактная Фабрика основана на композиции: создание объектов реализуется в методе, доступ к которому осуществляется через интерфейс фабрики. Задача Абстрактной Фабрики - создание семейств взаимосвязанных объектов без зависимости от их конкретных классов.
|
||||
|
||||
*Принцип:*
|
||||
- По возможности использовать абстракции в коде.
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Cheese.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Cheese
|
||||
{
|
||||
public:
|
||||
virtual std::string toString() const = 0;
|
||||
|
||||
virtual ~Cheese() {}
|
||||
};
|
||||
|
||||
class MozzarellaCheese: public Cheese
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Shredded Mozzarella";
|
||||
}
|
||||
};
|
||||
|
||||
class ParmesanCheese: public Cheese
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Shredded Parmesan";
|
||||
}
|
||||
};
|
||||
|
||||
class ReggianoCheese: public Cheese
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Reggiano Cheese";
|
||||
}
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* CheesePizza.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Pizza.hpp"
|
||||
#include "PizzaIngredientFactory.hpp"
|
||||
|
||||
class CheesePizza: public Pizza
|
||||
{
|
||||
public:
|
||||
PizzaIngredientFactory *ingredientFactory;
|
||||
|
||||
CheesePizza(PizzaIngredientFactory *ingredientFactory) : ingredientFactory(ingredientFactory) {}
|
||||
|
||||
void prepare() override
|
||||
{
|
||||
std::cout << "Preparing " << getName() << std::endl;
|
||||
setDough(ingredientFactory->createDough());
|
||||
setSauce(ingredientFactory->createSauce());
|
||||
setCheese(ingredientFactory->createCheese());
|
||||
}
|
||||
|
||||
~CheesePizza()
|
||||
{
|
||||
delete ingredientFactory;
|
||||
}
|
||||
};
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* ChicagoPizzaIngredientFactory.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PizzaIngredientFactory.hpp"
|
||||
#include "Cheese.hpp"
|
||||
#include "Sauce.hpp"
|
||||
#include "Dough.hpp"
|
||||
#include "Veggies.hpp"
|
||||
#include "Pepperoni.hpp"
|
||||
#include "Clams.hpp"
|
||||
|
||||
class ChicagoPizzaIngredientFactory: public PizzaIngredientFactory
|
||||
{
|
||||
public:
|
||||
Dough* createDough() const override
|
||||
{
|
||||
return new ThickCrustDough();
|
||||
}
|
||||
|
||||
Sauce* createSauce() const override
|
||||
{
|
||||
return new PlumTomatoSauce();
|
||||
}
|
||||
|
||||
Cheese* createCheese() const override
|
||||
{
|
||||
return new MozzarellaCheese();
|
||||
}
|
||||
|
||||
std::vector<Veggies*> createVeggies() const override
|
||||
{
|
||||
std::vector<Veggies*> veggies { new BlackOlivesVeggies(), new SpinachVeggies(), new EggplantVeggies() };
|
||||
|
||||
return veggies;
|
||||
}
|
||||
|
||||
Pepperoni* createPepperoni() const override
|
||||
{
|
||||
return new SlicedPepperoni();
|
||||
}
|
||||
|
||||
Clams* createClam() const override
|
||||
{
|
||||
return new FrozenClams();
|
||||
}
|
||||
};
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* ChicagoPizzaStore.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PizzaStore.hpp"
|
||||
#include "CheesePizza.hpp"
|
||||
#include "PepperoniPizza.hpp"
|
||||
#include "VeggiePizza.hpp"
|
||||
#include "ClamPizza.hpp"
|
||||
#include "StandardPizza.hpp"
|
||||
#include "NYPizzaIngredientFactory.hpp"
|
||||
|
||||
class ChicagoPizzaStore: public PizzaStore
|
||||
{
|
||||
public:
|
||||
Pizza* createPizza(const std::string &type) const override
|
||||
{
|
||||
Pizza *pizza = NULL;
|
||||
PizzaIngredientFactory *ingredientFactory = new NYPizzaIngredientFactory();
|
||||
|
||||
if (type == "cheese")
|
||||
{
|
||||
pizza = new CheesePizza(ingredientFactory);
|
||||
pizza->setName("Chicago Style Cheese Pizza");
|
||||
}
|
||||
else if (type == "veggie")
|
||||
{
|
||||
pizza = new VeggiePizza(ingredientFactory);
|
||||
pizza->setName("Chicago Style Veggie Pizza");
|
||||
}
|
||||
else if (type == "clam")
|
||||
{
|
||||
pizza = new ClamPizza(ingredientFactory);
|
||||
pizza->setName("Chicago Style Clam Pizza");
|
||||
}
|
||||
else if (type == "pepperoni")
|
||||
{
|
||||
pizza = new PepperoniPizza(ingredientFactory);
|
||||
pizza->setName("Chicago Style Pepperoni Pizza");
|
||||
}
|
||||
else
|
||||
{
|
||||
pizza = new StandardPizza(ingredientFactory);
|
||||
pizza->setName("Chicago Style Standard Pizza");
|
||||
}
|
||||
|
||||
return pizza;
|
||||
}
|
||||
};
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* ClamPizza.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Pizza.hpp"
|
||||
#include "PizzaIngredientFactory.hpp"
|
||||
|
||||
class ClamPizza: public Pizza
|
||||
{
|
||||
public:
|
||||
PizzaIngredientFactory *ingredientFactory;
|
||||
|
||||
ClamPizza(PizzaIngredientFactory *ingredientFactory) : ingredientFactory(ingredientFactory) {}
|
||||
|
||||
void prepare() override
|
||||
{
|
||||
std::cout << "Preparing " << getName() << std::endl;
|
||||
setDough(ingredientFactory->createDough());
|
||||
setSauce(ingredientFactory->createSauce());
|
||||
setCheese(ingredientFactory->createCheese());
|
||||
setClams(ingredientFactory->createClam());
|
||||
}
|
||||
|
||||
~ClamPizza()
|
||||
{
|
||||
delete ingredientFactory;
|
||||
}
|
||||
};
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Clams.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Clams
|
||||
{
|
||||
public:
|
||||
virtual std::string toString() const = 0;
|
||||
|
||||
virtual ~Clams() {}
|
||||
};
|
||||
|
||||
class FreshClams: public Clams
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Fresh Clams from Long Island Sound";
|
||||
}
|
||||
};
|
||||
|
||||
class FrozenClams: public Clams
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Frozen Clams from Chesapeake Bay";
|
||||
}
|
||||
};
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Dough.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Dough
|
||||
{
|
||||
public:
|
||||
virtual std::string toString() const = 0;
|
||||
|
||||
virtual ~Dough() {}
|
||||
};
|
||||
|
||||
class ThinCrustDough: public Dough
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Thin Crust Dough";
|
||||
}
|
||||
};
|
||||
|
||||
class ThickCrustDough: public Dough
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "ThickCrust style extra thick crust dough";
|
||||
}
|
||||
};
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* NYPizzaIngredientFactory.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PizzaIngredientFactory.hpp"
|
||||
#include "Cheese.hpp"
|
||||
#include "Sauce.hpp"
|
||||
#include "Dough.hpp"
|
||||
#include "Veggies.hpp"
|
||||
#include "Pepperoni.hpp"
|
||||
#include "Clams.hpp"
|
||||
|
||||
class NYPizzaIngredientFactory: public PizzaIngredientFactory
|
||||
{
|
||||
public:
|
||||
Dough* createDough() const override
|
||||
{
|
||||
return new ThinCrustDough();
|
||||
}
|
||||
|
||||
Sauce* createSauce() const override
|
||||
{
|
||||
return new MarinaraSauce();
|
||||
}
|
||||
|
||||
Cheese* createCheese() const override
|
||||
{
|
||||
return new ReggianoCheese();
|
||||
}
|
||||
|
||||
std::vector<Veggies*> createVeggies() const override
|
||||
{
|
||||
std::vector<Veggies*> veggies { new GarlicVeggies(), new OnionVeggies(), new MushroomVeggies(), new RedPepperVeggies() };
|
||||
|
||||
return veggies;
|
||||
}
|
||||
|
||||
Pepperoni* createPepperoni() const override
|
||||
{
|
||||
return new SlicedPepperoni();
|
||||
}
|
||||
|
||||
Clams* createClam() const override
|
||||
{
|
||||
return new FreshClams();
|
||||
}
|
||||
};
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* NYPizzaStore.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PizzaStore.hpp"
|
||||
#include "CheesePizza.hpp"
|
||||
#include "PepperoniPizza.hpp"
|
||||
#include "VeggiePizza.hpp"
|
||||
#include "ClamPizza.hpp"
|
||||
#include "StandardPizza.hpp"
|
||||
#include "NYPizzaIngredientFactory.hpp"
|
||||
|
||||
class NYPizzaStore: public PizzaStore
|
||||
{
|
||||
public:
|
||||
Pizza* createPizza(const std::string &type) const override
|
||||
{
|
||||
Pizza *pizza = NULL;
|
||||
PizzaIngredientFactory *ingredientFactory = new NYPizzaIngredientFactory();
|
||||
|
||||
if (type == "cheese")
|
||||
{
|
||||
pizza = new CheesePizza(ingredientFactory);
|
||||
pizza->setName("New York Style Cheese Pizza");
|
||||
}
|
||||
else if (type == "veggie")
|
||||
{
|
||||
pizza = new VeggiePizza(ingredientFactory);
|
||||
pizza->setName("New York Style Veggie Pizza");
|
||||
}
|
||||
else if (type == "clam")
|
||||
{
|
||||
pizza = new ClamPizza(ingredientFactory);
|
||||
pizza->setName("New York Style Clam Pizza");
|
||||
}
|
||||
else if (type == "pepperoni")
|
||||
{
|
||||
pizza = new PepperoniPizza(ingredientFactory);
|
||||
pizza->setName("New York Style Pepperoni Pizza");
|
||||
}
|
||||
else
|
||||
{
|
||||
pizza = new StandardPizza(ingredientFactory);
|
||||
pizza->setName("New York Style Standard Pizza");
|
||||
}
|
||||
|
||||
return pizza;
|
||||
}
|
||||
};
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Pepperoni.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Pepperoni {
|
||||
public:
|
||||
virtual std::string toString() const = 0;
|
||||
|
||||
virtual ~Pepperoni() {}
|
||||
};
|
||||
|
||||
class SlicedPepperoni: public Pepperoni
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Sliced Pepperoni";
|
||||
}
|
||||
};
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* PepperoniPizza.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Pizza.hpp"
|
||||
#include "PizzaIngredientFactory.hpp"
|
||||
|
||||
class PepperoniPizza: public Pizza
|
||||
{
|
||||
public:
|
||||
PizzaIngredientFactory *ingredientFactory;
|
||||
|
||||
PepperoniPizza(PizzaIngredientFactory *ingredientFactory) : ingredientFactory(ingredientFactory) {}
|
||||
|
||||
void prepare() override
|
||||
{
|
||||
std::cout << "Preparing " << getName() << std::endl;
|
||||
setDough(ingredientFactory->createDough());
|
||||
setSauce(ingredientFactory->createSauce());
|
||||
setCheese(ingredientFactory->createCheese());
|
||||
setVeggies(ingredientFactory->createVeggies());
|
||||
setPepperoni(ingredientFactory->createPepperoni());
|
||||
}
|
||||
|
||||
~PepperoniPizza()
|
||||
{
|
||||
delete ingredientFactory;
|
||||
}
|
||||
};
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* Pizza.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include "Dough.hpp"
|
||||
#include "Sauce.hpp"
|
||||
#include "Cheese.hpp"
|
||||
#include "Veggies.hpp"
|
||||
#include "Pepperoni.hpp"
|
||||
#include "Clams.hpp"
|
||||
|
||||
class Pizza
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
|
||||
Dough *dough = NULL;
|
||||
Sauce *sauce = NULL;
|
||||
std::vector<Veggies*> veggies;
|
||||
Cheese *cheese = NULL;
|
||||
Pepperoni *pepperoni = NULL;
|
||||
Clams *clam = NULL;
|
||||
public:
|
||||
|
||||
virtual void prepare() = 0;
|
||||
|
||||
virtual void bake() const
|
||||
{
|
||||
std::cout << "Bake for 25 minutes at 350" << std::endl;
|
||||
}
|
||||
|
||||
virtual void cut() const
|
||||
{
|
||||
std::cout << "Cutting the pizza into diagonal slices" << std::endl;
|
||||
}
|
||||
|
||||
virtual void box() const
|
||||
{
|
||||
std::cout << "Place pizza in official PizzaStore box" << std::endl;
|
||||
}
|
||||
|
||||
virtual std::string getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
virtual void setName(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
virtual void setDough(Dough *dough)
|
||||
{
|
||||
this->dough = dough;
|
||||
}
|
||||
virtual void setSauce(Sauce *sauce)
|
||||
{
|
||||
this->sauce = sauce;
|
||||
}
|
||||
virtual void setVeggies(const std::vector<Veggies*> &veggies)
|
||||
{
|
||||
this->veggies = veggies;
|
||||
}
|
||||
virtual void setCheese(Cheese *cheese)
|
||||
{
|
||||
this->cheese = cheese;
|
||||
}
|
||||
virtual void setPepperoni(Pepperoni *pepperoni)
|
||||
{
|
||||
this->pepperoni = pepperoni;
|
||||
}
|
||||
virtual void setClams(Clams *clam)
|
||||
{
|
||||
this->clam = clam;
|
||||
}
|
||||
|
||||
void toString()
|
||||
{
|
||||
std::cout << "---- " << name << " ----" << std::endl;
|
||||
|
||||
if (dough)
|
||||
{
|
||||
std::cout << '\t' << dough->toString() << std::endl;
|
||||
}
|
||||
if (sauce)
|
||||
{
|
||||
std::cout << '\t' << sauce->toString() << std::endl;
|
||||
}
|
||||
if (cheese)
|
||||
{
|
||||
std::cout << '\t' << cheese->toString() << std::endl;
|
||||
}
|
||||
if (!veggies.empty())
|
||||
{
|
||||
std::cout << '\t';
|
||||
for (size_t i = 0; i < veggies.size(); i++)
|
||||
{
|
||||
std::cout << veggies[i]->toString();
|
||||
|
||||
if (i < veggies.size() - 1)
|
||||
{
|
||||
std::cout << ", ";
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
if (clam)
|
||||
{
|
||||
std::cout << '\t' << clam->toString() << std::endl;
|
||||
}
|
||||
if (pepperoni)
|
||||
{
|
||||
std::cout << '\t' << pepperoni->toString() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~Pizza()
|
||||
{
|
||||
if (dough) delete dough;
|
||||
if (sauce) delete sauce;
|
||||
if (cheese) delete cheese;
|
||||
if (pepperoni) delete pepperoni;
|
||||
if (clam) delete clam;
|
||||
|
||||
for (auto vegetable : veggies)
|
||||
{
|
||||
delete vegetable;
|
||||
}
|
||||
}
|
||||
};
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* PizzaIngredientFactory.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Dough.hpp"
|
||||
#include "Sauce.hpp"
|
||||
#include "Cheese.hpp"
|
||||
#include "Veggies.hpp"
|
||||
#include "Pepperoni.hpp"
|
||||
#include "Clams.hpp"
|
||||
#include <vector>
|
||||
|
||||
class PizzaIngredientFactory
|
||||
{
|
||||
public:
|
||||
virtual Dough* createDough() const = 0;
|
||||
virtual Sauce* createSauce() const = 0;
|
||||
virtual Cheese* createCheese() const = 0;
|
||||
virtual std::vector<Veggies*> createVeggies() const = 0;
|
||||
virtual Pepperoni* createPepperoni() const = 0;
|
||||
virtual Clams* createClam() const = 0;
|
||||
|
||||
virtual ~PizzaIngredientFactory() {}
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* PizzaStore.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Pizza.hpp"
|
||||
|
||||
class PizzaStore
|
||||
{
|
||||
public:
|
||||
virtual Pizza* orderPizza(const std::string &type) const
|
||||
{
|
||||
Pizza *pizza = createPizza(type);
|
||||
|
||||
std::cout << "--- Making a " << pizza->getName() << " ---" << std::endl;
|
||||
|
||||
pizza->prepare();
|
||||
pizza->bake();
|
||||
pizza->cut();
|
||||
pizza->box();
|
||||
|
||||
return pizza;
|
||||
}
|
||||
|
||||
virtual Pizza* createPizza(const std::string &type) const = 0;
|
||||
|
||||
virtual ~PizzaStore() {}
|
||||
};
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Sauce.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Sauce
|
||||
{
|
||||
public:
|
||||
virtual std::string toString() const = 0;
|
||||
|
||||
virtual ~Sauce() {}
|
||||
};
|
||||
|
||||
class MarinaraSauce: public Sauce
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Marinara Sauce";
|
||||
}
|
||||
};
|
||||
|
||||
class PlumTomatoSauce: public Sauce
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Tomato sauce with plum tomatoes";
|
||||
}
|
||||
};
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* StandardPizza.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Pizza.hpp"
|
||||
#include "PizzaIngredientFactory.hpp"
|
||||
|
||||
class StandardPizza: public Pizza
|
||||
{
|
||||
public:
|
||||
PizzaIngredientFactory *ingredientFactory;
|
||||
|
||||
StandardPizza(PizzaIngredientFactory *ingredientFactory) : ingredientFactory(ingredientFactory) {}
|
||||
|
||||
void prepare() override
|
||||
{
|
||||
std::cout << "Preparing " << getName() << std::endl;
|
||||
}
|
||||
|
||||
~StandardPizza()
|
||||
{
|
||||
delete ingredientFactory;
|
||||
}
|
||||
};
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* VeggiePizza.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Pizza.hpp"
|
||||
#include "PizzaIngredientFactory.hpp"
|
||||
|
||||
class VeggiePizza: public Pizza
|
||||
{
|
||||
public:
|
||||
PizzaIngredientFactory *ingredientFactory;
|
||||
|
||||
VeggiePizza(PizzaIngredientFactory *ingredientFactory) : ingredientFactory(ingredientFactory) {}
|
||||
|
||||
void prepare() override
|
||||
{
|
||||
std::cout << "Preparing " << getName() << std::endl;
|
||||
setDough(ingredientFactory->createDough());
|
||||
setSauce(ingredientFactory->createSauce());
|
||||
setCheese(ingredientFactory->createCheese());
|
||||
setVeggies(ingredientFactory->createVeggies());
|
||||
}
|
||||
|
||||
~VeggiePizza()
|
||||
{
|
||||
delete ingredientFactory;
|
||||
}
|
||||
};
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Veggies.hpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Veggies {
|
||||
public:
|
||||
virtual std::string toString() const = 0;
|
||||
|
||||
virtual ~Veggies() {}
|
||||
};
|
||||
|
||||
class BlackOlivesVeggies: public Veggies
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Black Olives";
|
||||
}
|
||||
};
|
||||
|
||||
class EggplantVeggies: public Veggies
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Eggplant";
|
||||
}
|
||||
};
|
||||
|
||||
class MushroomVeggies: public Veggies
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Mushrooms";
|
||||
}
|
||||
};
|
||||
|
||||
class GarlicVeggies: public Veggies
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Garlic";
|
||||
}
|
||||
};
|
||||
|
||||
class RedPepperVeggies: public Veggies
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Red Pepper";
|
||||
}
|
||||
};
|
||||
|
||||
class SpinachVeggies: public Veggies
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Spinach";
|
||||
}
|
||||
};
|
||||
|
||||
class OnionVeggies: public Veggies
|
||||
{
|
||||
public:
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "Onion";
|
||||
}
|
||||
};
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* main.cpp
|
||||
*
|
||||
* Created on: 3 нояб. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#include "NYPizzaStore.hpp"
|
||||
#include "ChicagoPizzaStore.hpp"
|
||||
#include <vector>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<std::string> stylesPizza {"cheese", "clam", "pepperoni", "veggie"};
|
||||
|
||||
PizzaStore *nyStore = new NYPizzaStore();
|
||||
PizzaStore *chicagoStore = new ChicagoPizzaStore();
|
||||
Pizza *pizza = NULL;
|
||||
|
||||
for (const std::string &style : stylesPizza)
|
||||
{
|
||||
pizza = nyStore->orderPizza(style);
|
||||
std::cout << "Ethan ordered a " << pizza->getName() << std::endl;
|
||||
pizza->toString();
|
||||
delete pizza;
|
||||
pizza = chicagoStore->orderPizza(style);
|
||||
std::cout << "Joel ordered a " << pizza->getName() << std::endl;
|
||||
pizza->toString();
|
||||
delete pizza;
|
||||
}
|
||||
|
||||
delete nyStore;
|
||||
delete chicagoStore;
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue