Repository navigation
Expand file tree
/
Copy pathmultipleInheritance.cpp
More file actions
executable file
·102 lines (88 loc) · 2.65 KB
/
Copy pathmultipleInheritance.cpp
File metadata and controls
executable file
·102 lines (88 loc) · 2.65 KB
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
#include "../utils.hpp"
#include <stdlib.h>
#include <string>
#include <iostream>
class NumbersGenerator {
public:
NumbersGenerator(int length) : length(length) {}
virtual std::string generate() {
std::string generated;
for (int i = 0; i < length; ++i)
generated += generateSymbol();
return generated;
}
protected:
int length;
virtual std::string generateSymbol() {
int symbol = rand() % length;
return std::to_string(symbol);
}
};
class SymbolsGenerator : public NumbersGenerator {
public:
SymbolsGenerator(int length) : NumbersGenerator(length) {}
private:
virtual std::string generateSymbol() override {
int symbol = rand() % 97 + 50;
std::string str;
str += (char)symbol;
return str;
}
};
class SaltGenerator : public NumbersGenerator {
public:
SaltGenerator(int length) : NumbersGenerator(length) {}
private:
virtual std::string generateSymbol() override {
int symbol = rand() % (70 + length) + (50 + length);
std::string str;
str += (char)symbol;
return str;
}
};
class HashGenerator : public SymbolsGenerator, public SaltGenerator {
public:
HashGenerator(int symbols, int salt) :
SymbolsGenerator(symbols), SaltGenerator(salt) {}
std::string generate() override {
std::string base = SymbolsGenerator::generate();
std::string salt = SaltGenerator::generate();
return salt + "." + base;
}
};
class HashGeneratorEncapsulated {
public:
HashGeneratorEncapsulated(int symbols, int salt) :
symbolsGenerator(symbols), saltGenerator(salt) {}
std::string generate() {
std::string base = symbolsGenerator.generate();
std::string salt = saltGenerator.generate();
return salt + "." + base;
}
private:
SymbolsGenerator symbolsGenerator;
SaltGenerator saltGenerator;
};
class HashGeneratorInjectable {
public:
HashGeneratorInjectable(SymbolsGenerator& symbolsGenerator, SaltGenerator& saltGenerator) :
symbolsGenerator(symbolsGenerator), saltGenerator(saltGenerator) {}
std::string generate() {
std::string base = symbolsGenerator.generate();
std::string salt = saltGenerator.generate();
return salt + "." + base;
}
private:
SymbolsGenerator& symbolsGenerator;
SaltGenerator& saltGenerator;
};
namespace utils {
void multipleInheritance() {
// auto symbols = SymbolsGenerator(10);
// auto salt = SaltGenerator(5);
// auto g = HashGeneratorInjectable(symbols, salt);
// auto g = HashGeneratorEncapsulated(10, 5);
auto g = HashGenerator(10, 5);
std::cout << g.generate() << std::endl;
}
}