-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractFactory.h
102 lines (77 loc) · 2.77 KB
/
AbstractFactory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//============================================================================
// Name : ChainOfResponsibility.h
// Created on : 19.04.2020
// Author : Tokmakov Andrey
// Version : 1.0
// Copyright : Your copyright notice
// Description : Chain of pesponsibility pattern tests
//============================================================================
#ifndef ABSTRACT_FACTORY_PATTERN_TESTS__H_
#define ABSTRACT_FACTORY_PATTERN_TESTS__H_
#include <iostream>
#include <string>
#include <memory>
namespace AbstractFactory_Pattern_Tests {
class IAbstractProductA;
class IAbstractProductB;
class IAbstractFactory {
public:
virtual std::shared_ptr<IAbstractProductA> createProductA() = 0;
virtual std::shared_ptr<IAbstractProductB> createProductB() = 0;
};
class IProduct {
public:
virtual const std::string getName() const noexcept = 0;
};
class IAbstractProductA: public IProduct {
public:
virtual void interact(std::shared_ptr<IAbstractProductB> b) = 0;
virtual const std::string getName() const noexcept = 0;
};
class IAbstractProductB {
public:
virtual void interact(std::shared_ptr<IAbstractProductA> a) = 0;
virtual const std::string getName() const noexcept = 0;
};
class ConcreteFactory1: public IAbstractFactory {
public:
virtual std::shared_ptr<IAbstractProductA> createProductA() override;
virtual std::shared_ptr<IAbstractProductB> createProductB() override;
};
class ConcreteFactory2 : public IAbstractFactory {
public:
virtual std::shared_ptr<IAbstractProductA> createProductA() override;
virtual std::shared_ptr<IAbstractProductB> createProductB() override;
};
class ProductA1 : public IAbstractProductA {
public:
virtual void interact(std::shared_ptr<IAbstractProductB> product) override;
virtual const std::string getName() const noexcept override;
};
class ProductB1 : public IAbstractProductB {
public:
virtual void interact(std::shared_ptr<IAbstractProductA> product) override;
virtual const std::string getName() const noexcept override;
};
class ProductA2 : public IAbstractProductA {
public:
virtual void interact(std::shared_ptr<IAbstractProductB> product) override;
virtual const std::string getName() const noexcept override;
};
class ProductB2 : public IAbstractProductB {
public:
virtual void interact(std::shared_ptr<IAbstractProductA> product) override;
virtual const std::string getName() const noexcept override;
};
class Client {
private:
std::shared_ptr<IAbstractProductA> productA;
std::shared_ptr<IAbstractProductB> productB;
public:
Client(std::shared_ptr<IAbstractFactory> factory);
public:
virtual void execute();
};
void Test();
};
#endif // !ABSTRACT_FACTORY_PATTERN_TESTS__H_