Skip to content

Commit 7694c44

Browse files
committed
add morning facade example to facade
1 parent 8a9d1a4 commit 7694c44

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

structural_design_pattern/facade/README.md

+69
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [Definitions](#Definitions)
2020
- [What Problem Facade Solve](#What-Problem-Facade-Solve)
2121
- [Examples](#Examples)
22+
- [Morning Facade Example](#Morning-Facade-Example)
2223
- [file converter example ](#file-converter-example)
2324
- [Shape Maker](#Shape-Maker) Tutorial point Example
2425
- [Sources](#Sources)
@@ -64,6 +65,74 @@
6465

6566
## **Examples**
6667

68+
### Morning Facade Example
69+
source: GOF <a href="https://github.com/scottt2/design-patterns-in-dart/tree/master/facade" target="_blank">scottt2 design-patterns-in-dart facade</a>
70+
71+
#### all classes needed to be implemented
72+
```dart
73+
class Grinder {
74+
String _type;
75+
76+
Grinder(this._type);
77+
void grind() => print("Grinding $_type!");
78+
}
79+
80+
class Maker {
81+
String _type;
82+
83+
Maker(this._type);
84+
void fill() => print("Filling the $_type maker!");
85+
void retrieve() => print("Retrieving the $_type!");
86+
void start() => print("Starting the $_type maker!");
87+
}
88+
89+
class Imbiber {
90+
String _beverage;
91+
92+
Imbiber(this._beverage);
93+
void drink() => print("Mmmmm...drinking $_beverage!");
94+
}
95+
```
96+
#### facade class
97+
```dart
98+
class MorningFacade {
99+
final _coffeeDrinker = Imbiber("coffee");
100+
final _coffeeGrinder = Grinder("coffee beans");
101+
final _coffeeMaker = Maker("coffee");
102+
103+
void prepareCoffee() {
104+
print("\r\nPreparing the coffee...");
105+
_coffeeGrinder.grind();
106+
_coffeeMaker
107+
..fill()
108+
..start();
109+
print("Coffee is brewing!\r\n");
110+
}
111+
112+
void drinkCoffee() {
113+
print("\r\nMust...have...coffee...");
114+
_coffeeMaker.retrieve();
115+
_coffeeDrinker.drink();
116+
print("This is damn fine coffee!");
117+
}
118+
}
119+
```
120+
#### main() to test
121+
```dart
122+
void main() {
123+
var typicalMorning = MorningFacade();
124+
125+
print("Wake up! Grab a brush and put on a little makeup...");
126+
print("\r\nStumble to the kitchen...");
127+
128+
typicalMorning.prepareCoffee();
129+
print("Oh my...that smells good...");
130+
131+
typicalMorning.drinkCoffee();
132+
print("\r\nI'm ready to attack the day!");
133+
}
134+
135+
```
67136
### file converter example
68137
- Example in dart: <a href="file_converter/" target="_blank">file converter example </a>
69138

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Morning Facade Example
2+
class Grinder {
3+
String _type;
4+
5+
Grinder(this._type);
6+
void grind() => print("Grinding $_type!");
7+
}
8+
9+
class Maker {
10+
String _type;
11+
12+
Maker(this._type);
13+
void fill() => print("Filling the $_type maker!");
14+
void retrieve() => print("Retrieving the $_type!");
15+
void start() => print("Starting the $_type maker!");
16+
}
17+
18+
class Imbiber {
19+
String _beverage;
20+
21+
Imbiber(this._beverage);
22+
void drink() => print("Mmmmm...drinking $_beverage!");
23+
}
24+
25+
class MorningFacade {
26+
final _coffeeDrinker = Imbiber("coffee");
27+
final _coffeeGrinder = Grinder("coffee beans");
28+
final _coffeeMaker = Maker("coffee");
29+
30+
void prepareCoffee() {
31+
print("\r\nPreparing the coffee...");
32+
_coffeeGrinder.grind();
33+
_coffeeMaker
34+
..fill()
35+
..start();
36+
print("Coffee is brewing!\r\n");
37+
}
38+
39+
void drinkCoffee() {
40+
print("\r\nMust...have...coffee...");
41+
_coffeeMaker.retrieve();
42+
_coffeeDrinker.drink();
43+
print("This is damn fine coffee!");
44+
}
45+
}
46+
47+
void main() {
48+
var typicalMorning = MorningFacade();
49+
50+
print("Wake up! Grab a brush and put on a little makeup...");
51+
print("\r\nStumble to the kitchen...");
52+
53+
typicalMorning.prepareCoffee();
54+
print("Oh my...that smells good...");
55+
56+
typicalMorning.drinkCoffee();
57+
print("\r\nI'm ready to attack the day!");
58+
}

0 commit comments

Comments
 (0)