File tree Expand file tree Collapse file tree 1 file changed +45
-1
lines changed Expand file tree Collapse file tree 1 file changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -325,7 +325,50 @@ tuple.y
325
325
tuple.z
326
326
```
327
327
328
- ##🚧 Bridge
328
+ ##🌉 Bridge
329
+ ``` swift
330
+ protocol Switch {
331
+ var appliance: Appliance {get set }
332
+ func turnOn ()
333
+ }
334
+
335
+ protocol Appliance {
336
+ func run ()
337
+ }
338
+
339
+ class RemoteControl : Switch {
340
+ var appliance: Appliance
341
+ func turnOn () {
342
+ self .appliance .run ()
343
+ }
344
+
345
+ init (appliance : Appliance) {
346
+ self .appliance = appliance
347
+ }
348
+ }
349
+
350
+ class TV : Appliance {
351
+ func run () {
352
+ println (" tv turned on" );
353
+ }
354
+ }
355
+
356
+ class VacuumCleaner : Appliance {
357
+ func run () {
358
+ println (" vacuum cleaner turned on" )
359
+ }
360
+ }
361
+ ```
362
+
363
+ ** Usage**
364
+ ``` swift
365
+ var tvRemoteControl = RemoteControl (appliance : TV ())
366
+ tvRemoteControl.turnOn ()
367
+
368
+ var fancyVacuumCleanerRemoteControl = RemoteControl (appliance : VacuumCleaner ())
369
+ fancyVacuumCleanerRemoteControl.turnOn ()
370
+ ```
371
+
329
372
##🍧 Decorator
330
373
331
374
``` swift
@@ -393,6 +436,7 @@ someCoffee = WhipCoffee(decoratedCoffee: someCoffee)
393
436
println (" Cost : \( someCoffee.getCost () ) ; Ingredients: \( someCoffee.getIngredients () ) " )
394
437
```
395
438
439
+
396
440
##🚧 Proxy
397
441
398
442
#Behavioral
You can’t perform that action at this time.
0 commit comments