File tree Expand file tree Collapse file tree 4 files changed +59
-3
lines changed Expand file tree Collapse file tree 4 files changed +59
-3
lines changed Original file line number Diff line number Diff line change @@ -65,5 +65,5 @@ add_executable(jalgorithmCPP
65
65
Implementation/Array/SpiralMatrix.h
66
66
DesignPattern/Creational/AbstractFactory.h
67
67
DesignPattern/Structural/Adapter.h
68
- )
68
+ DesignPattern/Behavioral/Iterator.h DesignPattern/Creational/Builder.h )
69
69
Original file line number Diff line number Diff line change
1
+ // Check out CustomDataStructure/Deque.h
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by Jacob Lo on Feb 19, 2019
3
+ //
4
+
5
+ #pragma once
6
+ #include < iostream>
7
+
8
+ using namespace std ;
9
+
10
+ namespace Builder {
11
+ class Car {
12
+ Car (string c, string e) : color(c), engine(e){}
13
+
14
+ public:
15
+ const string color, engine;
16
+
17
+ struct CarBuilder {
18
+ string color = " Red" , engine = " Boxer" ;
19
+
20
+ public:
21
+ CarBuilder& setColor (string c) {
22
+ this ->color = c;
23
+ return *this ;
24
+ }
25
+ CarBuilder& setEngine (string e) {
26
+ this ->engine = e;
27
+ return *this ;
28
+ }
29
+
30
+ Car build () {
31
+ return Car (color, engine);
32
+ }
33
+ };
34
+ };
35
+
36
+ ostream& operator << ( ostream& out, const Car& c) {
37
+ out << " This is a " << c.color << " color car with " << c.engine << " engine." << endl;
38
+ return out;
39
+ }
40
+
41
+ void test () {
42
+ Car c1 = Car::CarBuilder ().setColor (" Blue" ).setEngine (" Inline" ).build ();
43
+ Car c2 = Car::CarBuilder ().setColor (" Black" ).setEngine (" V6" ).build ();
44
+
45
+ Car::CarBuilder builder;
46
+ Car c3 = builder.build ();
47
+
48
+ builder.setColor (" Green" );
49
+ Car c4 = builder.build ();
50
+
51
+ builder.setEngine (" V8" );
52
+ Car c5 = builder.build ();
53
+
54
+ cout << c1 << c2 << c3 << c4 << c5;
55
+ }
56
+
57
+ }
Original file line number Diff line number Diff line change 20
20
21
21
using namespace std ;
22
22
23
-
24
-
25
23
int main () {
26
24
27
25
}
You can’t perform that action at this time.
0 commit comments