|
19 | 19 | - [Definitions](#Definitions)
|
20 | 20 | - [What Problem Facade Solve](#What-Problem-Facade-Solve)
|
21 | 21 | - [Examples](#Examples)
|
| 22 | + - [Morning Facade Example](#Morning-Facade-Example) |
22 | 23 | - [file converter example ](#file-converter-example)
|
23 | 24 | - [Shape Maker](#Shape-Maker) Tutorial point Example
|
24 | 25 | - [Sources](#Sources)
|
|
64 | 65 |
|
65 | 66 | ## **Examples**
|
66 | 67 |
|
| 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 | +``` |
67 | 136 | ### file converter example
|
68 | 137 | - Example in dart: <a href="file_converter/" target="_blank">file converter example </a>
|
69 | 138 |
|
|
0 commit comments