Compare commits

..

No commits in common. "lesson_4" and "master" have entirely different histories.

16 changed files with 0 additions and 481 deletions

View File

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

View File

@ -1,43 +0,0 @@
/*
* ChicagoPizzaStore.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "PizzaStore.hpp"
#include "ChicagoStylePizza.hpp"
#include "ChicagoStyleCheesePizza.hpp"
#include "ChicagoStyleVeggiePizza.hpp"
#include "ChicagoStyleClamPizza.hpp"
#include "ChicagoStylePepperoniPizza.hpp"
class ChicagoPizzaStore: public PizzaStore
{
public:
Pizza createPizza(const std::string &type) const override
{
if (type == "cheese")
{
return ChicagoStyleCheesePizza();
}
else if (type == "veggie")
{
return ChicagoStyleVeggiePizza();
}
else if (type == "clam")
{
return ChicagoStyleClamPizza();
}
else if (type == "pepperoni")
{
return ChicagoStylePepperoniPizza();
}
else
{
return ChicagoStylePizza();
}
}
};

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;
}
};

View File

@ -1,43 +0,0 @@
/*
* NYPizzaStore.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "PizzaStore.hpp"
#include "NYStylePiza.hpp"
#include "NYStyleCheesePiza.hpp"
#include "NYStyleVeggiePizza.hpp"
#include "NYStyleClamPizza.hpp"
#include "NYStylePepperoniPizza.hpp"
class NYPizzaStore: public PizzaStore
{
public:
Pizza createPizza(const std::string &type) const override
{
if (type == "cheese")
{
return NYStyleCheesePiza();
}
else if (type == "veggie")
{
return NYStyleVeggiePizza();
}
else if (type == "clam")
{
return NYStyleClamPizza();
}
else if (type == "pepperoni")
{
return NYStylePepperoniPizza();
}
else
{
return NYStylePiza();
}
}
};

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");
}
};

View File

@ -1,75 +0,0 @@
/*
* Pizza.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include <iostream>
#include <list>
class Pizza
{
private:
std::string name;
std::string dough;
std::string sauce;
std::list<std::string> toppings;
public:
virtual void prepare() const
{
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
{
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(std::string dough)
{
this->dough = dough;
}
virtual void setSauce(std::string sauce)
{
this->sauce = sauce;
}
virtual void addTopping(std::string topping)
{
toppings.push_back(topping);
}
virtual ~Pizza() {}
};

View File

@ -1,30 +0,0 @@
/*
* PizzaStore.hpp
*
* Created on: 2 нояб. 2021 г.
* Author: alexander
*/
#pragma once
#include "Pizza.hpp"
class PizzaStore
{
public:
virtual Pizza orderPizza(const std::string &type) const
{
Pizza pizza = createPizza(type);
pizza.prepare();
pizza.bake();
pizza.cut();
pizza.box();
return pizza;
}
virtual Pizza createPizza(const std::string &type) const = 0;
virtual ~PizzaStore() {}
};

View File

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