factory with ingredients

This commit is contained in:
Alexander Zhirov 2021-11-03 18:35:58 +03:00
parent a44ab07735
commit 97ec325534
30 changed files with 732 additions and 315 deletions

View File

@ -0,0 +1,7 @@
Паттерн "Абстрактная Фабрика" предоставляет интерфейс для семейств взаимосвязанных объектов без указания их конкретных классов.
Все фабричные паттерны обеспечивают слабую связанность за счет сокращения зависимости приложения от конкретных классов.
Все фабрики инкапсулируют создание объектов. Абстрактная Фабрика основана на композиции: создание объектов реализуется в методе, доступ к которому осуществляется через интерфейс фабрики. Задача Абстрактной Фабрики - создание семейств взаимосвязанных объектов без зависимости от их конкретных классов.
*Принцип:*
- По возможности использовать абстракции в коде.

48
lesson_4/Cheese.hpp Normal file
View File

@ -0,0 +1,48 @@
/*
* 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";
}
};

32
lesson_4/CheesePizza.hpp Normal file
View File

@ -0,0 +1,32 @@
/*
* 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;
}
};

View File

@ -0,0 +1,52 @@
/*
* 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();
}
};

View File

@ -1,43 +1,54 @@
/* /*
* ChicagoPizzaStore.hpp * ChicagoPizzaStore.hpp
* *
* Created on: 2 нояб. 2021 г. * Created on: 3 нояб. 2021 г.
* Author: alexander * Author: alexander
*/ */
#pragma once #pragma once
#include "PizzaStore.hpp" #include "PizzaStore.hpp"
#include "ChicagoStylePizza.hpp" #include "CheesePizza.hpp"
#include "ChicagoStyleCheesePizza.hpp" #include "PepperoniPizza.hpp"
#include "ChicagoStyleVeggiePizza.hpp" #include "VeggiePizza.hpp"
#include "ChicagoStyleClamPizza.hpp" #include "ClamPizza.hpp"
#include "ChicagoStylePepperoniPizza.hpp" #include "StandardPizza.hpp"
#include "NYPizzaIngredientFactory.hpp"
class ChicagoPizzaStore: public PizzaStore class ChicagoPizzaStore: public PizzaStore
{ {
public: public:
Pizza createPizza(const std::string &type) const override Pizza* createPizza(const std::string &type) const override
{ {
Pizza *pizza = NULL;
PizzaIngredientFactory *ingredientFactory = new NYPizzaIngredientFactory();
if (type == "cheese") if (type == "cheese")
{ {
return ChicagoStyleCheesePizza(); pizza = new CheesePizza(ingredientFactory);
pizza->setName("Chicago Style Cheese Pizza");
} }
else if (type == "veggie") else if (type == "veggie")
{ {
return ChicagoStyleVeggiePizza(); pizza = new VeggiePizza(ingredientFactory);
pizza->setName("Chicago Style Veggie Pizza");
} }
else if (type == "clam") else if (type == "clam")
{ {
return ChicagoStyleClamPizza(); pizza = new ClamPizza(ingredientFactory);
pizza->setName("Chicago Style Clam Pizza");
} }
else if (type == "pepperoni") else if (type == "pepperoni")
{ {
return ChicagoStylePepperoniPizza(); pizza = new PepperoniPizza(ingredientFactory);
pizza->setName("Chicago Style Pepperoni Pizza");
} }
else else
{ {
return ChicagoStylePizza(); pizza = new StandardPizza(ingredientFactory);
pizza->setName("Chicago Style Standard Pizza");
} }
return pizza;
} }
}; };

View File

@ -1,28 +0,0 @@
/*
* ChicagoStyleCheesePizza.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "Pizza.hpp"
class ChicagoStyleCheesePizza: public Pizza
{
public:
ChicagoStyleCheesePizza()
{
setName("Chicago Style Deep Dish Cheese Pizza");
setDough("Extra Thick Crust Dough");
setSauce("Plum Tomato Sauce");
addTopping("Shredded Mozzarella Cheese");
}
void cut() const override
{
std::cout << "Cutting the pizza into square slices" << std::endl;
}
};

View File

@ -1,29 +0,0 @@
/*
* ChicagoStyleClamPizza.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "Pizza.hpp"
class ChicagoStyleClamPizza: public Pizza
{
public:
ChicagoStyleClamPizza()
{
setName("Chicago Style Clam Pizza");
setDough("Extra Thick Crust Dough");
setSauce("Plum Tomato Sauce");
addTopping("Shredded Mozzarella Cheese");
addTopping("Frozen Clams from Chesapeake Bay");
}
void cut() const override
{
std::cout << "Cutting the pizza into square slices" << std::endl;
}
};

View File

@ -1,32 +0,0 @@
/*
* ChicagoStylePepperoniPizza.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "Pizza.hpp"
class ChicagoStylePepperoniPizza: public Pizza
{
public:
ChicagoStylePepperoniPizza()
{
setName("Chicago Style Pepperoni Pizza");
setDough("Extra Thick Crust Dough");
setSauce("Plum Tomato Sauce");
addTopping("Shredded Mozzarella Cheese");
addTopping("Black Olives");
addTopping("Spinach");
addTopping("Eggplant");
addTopping("Sliced Pepperoni");
}
void cut() const override
{
std::cout << "Cutting the pizza into square slices" << std::endl;
}
};

View File

@ -1,14 +0,0 @@
/*
* ChicagoStylePizza.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "Pizza.hpp"
class ChicagoStylePizza: public Pizza
{
};

View File

@ -1,31 +0,0 @@
/*
* ChicagoStyleVeggiePizza.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "Pizza.hpp"
class ChicagoStyleVeggiePizza: public Pizza
{
public:
ChicagoStyleVeggiePizza()
{
setName("Chicago Deep Dish Veggie Pizza");
setDough("Extra Thick Crust Dough");
setSauce("Plum Tomato Sauce");
addTopping("Shredded Mozzarella Cheese");
addTopping("Black Olives");
addTopping("Spinach");
addTopping("Eggplant");
}
void cut() const override
{
std::cout << "Cutting the pizza into square slices" << std::endl;
}
};

33
lesson_4/ClamPizza.hpp Normal file
View File

@ -0,0 +1,33 @@
/*
* 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;
}
};

38
lesson_4/Clams.hpp Normal file
View File

@ -0,0 +1,38 @@
/*
* 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";
}
};

38
lesson_4/Dough.hpp Normal file
View File

@ -0,0 +1,38 @@
/*
* 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";
}
};

View File

@ -0,0 +1,52 @@
/*
* 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();
}
};

View File

@ -1,43 +1,54 @@
/* /*
* NYPizzaStore.hpp * NYPizzaStore.hpp
* *
* Created on: 2 нояб. 2021 г. * Created on: 3 нояб. 2021 г.
* Author: alexander * Author: alexander
*/ */
#pragma once #pragma once
#include "PizzaStore.hpp" #include "PizzaStore.hpp"
#include "NYStylePiza.hpp" #include "CheesePizza.hpp"
#include "NYStyleCheesePiza.hpp" #include "PepperoniPizza.hpp"
#include "NYStyleVeggiePizza.hpp" #include "VeggiePizza.hpp"
#include "NYStyleClamPizza.hpp" #include "ClamPizza.hpp"
#include "NYStylePepperoniPizza.hpp" #include "StandardPizza.hpp"
#include "NYPizzaIngredientFactory.hpp"
class NYPizzaStore: public PizzaStore class NYPizzaStore: public PizzaStore
{ {
public: public:
Pizza createPizza(const std::string &type) const override Pizza* createPizza(const std::string &type) const override
{ {
Pizza *pizza = NULL;
PizzaIngredientFactory *ingredientFactory = new NYPizzaIngredientFactory();
if (type == "cheese") if (type == "cheese")
{ {
return NYStyleCheesePiza(); pizza = new CheesePizza(ingredientFactory);
pizza->setName("New York Style Cheese Pizza");
} }
else if (type == "veggie") else if (type == "veggie")
{ {
return NYStyleVeggiePizza(); pizza = new VeggiePizza(ingredientFactory);
pizza->setName("New York Style Veggie Pizza");
} }
else if (type == "clam") else if (type == "clam")
{ {
return NYStyleClamPizza(); pizza = new ClamPizza(ingredientFactory);
pizza->setName("New York Style Clam Pizza");
} }
else if (type == "pepperoni") else if (type == "pepperoni")
{ {
return NYStylePepperoniPizza(); pizza = new PepperoniPizza(ingredientFactory);
pizza->setName("New York Style Pepperoni Pizza");
} }
else else
{ {
return NYStylePiza(); pizza = new StandardPizza(ingredientFactory);
pizza->setName("New York Style Standard Pizza");
} }
return pizza;
} }
}; };

View File

@ -1,23 +0,0 @@
/*
* NYStyleCheesePiza.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "Pizza.hpp"
class NYStyleCheesePiza: public Pizza
{
public:
NYStyleCheesePiza()
{
setName("NY Style Sauce and Cheese Pizza");
setDough("Thin Crust Dough");
setSauce("Marinara Sauce");
addTopping("Grated Reggiano Cheese");
}
};

View File

@ -1,24 +0,0 @@
/*
* NYStyleClamPizza.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "Pizza.hpp"
class NYStyleClamPizza: public Pizza
{
public:
NYStyleClamPizza()
{
setName("NY Style Clam Pizza");
setDough("Thin Crust Dough");
setSauce("Marinara Sauce");
addTopping("Grated Reggiano Cheese");
addTopping("Fresh Clams from Long Island Sound");
}
};

View File

@ -1,28 +0,0 @@
/*
* NYStylePepperoniPizza.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "Pizza.hpp"
class NYStylePepperoniPizza: public Pizza
{
public:
NYStylePepperoniPizza()
{
setName("NY Style Pepperoni Pizza");
setDough("Thin Crust Dough");
setSauce("Marinara Sauce");
addTopping("Grated Reggiano Cheese");
addTopping("Sliced Pepperoni");
addTopping("Garlic");
addTopping("Onion");
addTopping("Mushrooms");
addTopping("Red Pepper");
}
};

View File

@ -1,14 +0,0 @@
/*
* NYStylePiza.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "Pizza.hpp"
class NYStylePiza: public Pizza
{
};

View File

@ -1,27 +0,0 @@
/*
* NYStyleVeggiePizza.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "Pizza.hpp"
class NYStyleVeggiePizza: public Pizza
{
public:
NYStyleVeggiePizza()
{
setName("NY Style Veggie Pizza");
setDough("Thin Crust Dough");
setSauce("Marinara Sauce");
addTopping("Grated Reggiano Cheese");
addTopping("Garlic");
addTopping("Onion");
addTopping("Mushrooms");
addTopping("Red Pepper");
}
};

27
lesson_4/Pepperoni.hpp Normal file
View File

@ -0,0 +1,27 @@
/*
* 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";
}
};

View File

@ -0,0 +1,34 @@
/*
* 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;
}
};

View File

@ -1,35 +1,36 @@
/* /*
* Pizza.hpp * Pizza.hpp
* *
* Created on: 2 нояб. 2021 г. * Created on: 3 нояб. 2021 г.
* Author: alexander * Author: alexander
*/ */
#pragma once #pragma once
#include <iostream> #include <iostream>
#include <list> #include <vector>
#include <sstream>
#include "Dough.hpp"
#include "Sauce.hpp"
#include "Cheese.hpp"
#include "Veggies.hpp"
#include "Pepperoni.hpp"
#include "Clams.hpp"
class Pizza class Pizza
{ {
private: private:
std::string name; std::string name;
std::string dough;
std::string sauce; Dough *dough = NULL;
std::list<std::string> toppings; Sauce *sauce = NULL;
std::vector<Veggies*> veggies;
Cheese *cheese = NULL;
Pepperoni *pepperoni = NULL;
Clams *clam = NULL;
public: public:
virtual void prepare() const virtual void prepare() = 0;
{
std::cout << "Preparing " << name << std::endl;
std::cout << "Tossing dough..." << std::endl;
std::cout << "Adding sauce..." << std::endl;
std::cout << "Adding toppings:" << std::endl;
for (const std::string &topping : toppings)
{
std::cout << '\t' << topping << std::endl;
}
}
virtual void bake() const virtual void bake() const
{ {
@ -56,20 +57,82 @@ public:
this->name = name; this->name = name;
} }
virtual void setDough(std::string dough) virtual void setDough(Dough *dough)
{ {
this->dough = dough; this->dough = dough;
} }
virtual void setSauce(Sauce *sauce)
virtual void setSauce(std::string sauce)
{ {
this->sauce = sauce; this->sauce = sauce;
} }
virtual void setVeggies(const std::vector<Veggies*> &veggies)
virtual void addTopping(std::string topping)
{ {
toppings.push_back(topping); 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;
} }
virtual ~Pizza() {} 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;
}
}
}; };

View File

@ -0,0 +1,29 @@
/*
* 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() {}
};

View File

@ -1,7 +1,7 @@
/* /*
* PizzaStore.hpp * PizzaStore.hpp
* *
* Created on: 2 нояб. 2021 г. * Created on: 3 нояб. 2021 г.
* Author: alexander * Author: alexander
*/ */
@ -12,19 +12,21 @@
class PizzaStore class PizzaStore
{ {
public: public:
virtual Pizza orderPizza(const std::string &type) const virtual Pizza* orderPizza(const std::string &type) const
{ {
Pizza pizza = createPizza(type); Pizza *pizza = createPizza(type);
pizza.prepare(); std::cout << "--- Making a " << pizza->getName() << " ---" << std::endl;
pizza.bake();
pizza.cut(); pizza->prepare();
pizza.box(); pizza->bake();
pizza->cut();
pizza->box();
return pizza; return pizza;
} }
virtual Pizza createPizza(const std::string &type) const = 0; virtual Pizza* createPizza(const std::string &type) const = 0;
virtual ~PizzaStore() {} virtual ~PizzaStore() {}
}; };

38
lesson_4/Sauce.hpp Normal file
View File

@ -0,0 +1,38 @@
/*
* 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";
}
};

View File

@ -0,0 +1,29 @@
/*
* 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;
}
};

33
lesson_4/VeggiePizza.hpp Normal file
View File

@ -0,0 +1,33 @@
/*
* 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;
}
};

87
lesson_4/Veggies.hpp Normal file
View File

@ -0,0 +1,87 @@
/*
* 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";
}
};

View File

@ -1,29 +1,32 @@
/* /*
* main.cpp * main.cpp
* *
* Created on: 2 нояб. 2021 г. * Created on: 3 нояб. 2021 г.
* Author: alexander * Author: alexander
*/ */
#include <vector>
#include "NYPizzaStore.hpp" #include "NYPizzaStore.hpp"
#include "ChicagoPizzaStore.hpp" #include "ChicagoPizzaStore.hpp"
#include <vector>
int main() int main()
{ {
std::vector<std::string> pizzaTypes {"cheese", "clam", "pepperoni", "veggie"}; std::vector<std::string> stylesPizza {"cheese", "clam", "pepperoni", "veggie"};
PizzaStore *nyStore = new NYPizzaStore(); PizzaStore *nyStore = new NYPizzaStore();
PizzaStore *chicagoStore = new ChicagoPizzaStore(); PizzaStore *chicagoStore = new ChicagoPizzaStore();
Pizza pizza; Pizza *pizza = NULL;
for (const std::string &pizzaType : pizzaTypes) for (const std::string &style : stylesPizza)
{ {
pizza = nyStore->orderPizza(pizzaType); pizza = nyStore->orderPizza(style);
std::cout << "Ethan ordered a " << pizza.getName() << std::endl; std::cout << "Ethan ordered a " << pizza->getName() << std::endl;
pizza->toString();
pizza = chicagoStore->orderPizza(pizzaType); delete pizza;
std::cout << "Joel ordered a " << pizza.getName() << std::endl; pizza = chicagoStore->orderPizza(style);
std::cout << "Joel ordered a " << pizza->getName() << std::endl;
pizza->toString();
delete pizza;
} }
delete nyStore; delete nyStore;