Skip to content

Commit

Permalink
Merge branch 'tomkowz-master'
Browse files Browse the repository at this point in the history
* tomkowz-master:
  Added Bridge design pattern
  • Loading branch information
ochococo committed Sep 26, 2014
2 parents 9d5e563 + 8954547 commit d4131a9
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,50 @@ tuple.y
tuple.z
```

##🚧 Bridge
##🌉 Bridge
```swift
protocol Switch {
var appliance: Appliance {get set}
func turnOn()
}

protocol Appliance {
func run()
}

class RemoteControl: Switch {
var appliance: Appliance
func turnOn() {
self.appliance.run()
}

init(appliance: Appliance) {
self.appliance = appliance
}
}

class TV: Appliance {
func run() {
println("tv turned on");
}
}

class VacuumCleaner: Appliance {
func run() {
println("vacuum cleaner turned on")
}
}
```

**Usage**
```swift
var tvRemoteControl = RemoteControl(appliance: TV())
tvRemoteControl.turnOn()

var fancyVacuumCleanerRemoteControl = RemoteControl(appliance: VacuumCleaner())
fancyVacuumCleanerRemoteControl.turnOn()
```

##🍧 Decorator

```swift
Expand Down Expand Up @@ -393,6 +436,7 @@ someCoffee = WhipCoffee(decoratedCoffee: someCoffee)
println("Cost : \(someCoffee.getCost()); Ingredients: \(someCoffee.getIngredients())")
```


##🚧 Proxy

#Behavioral
Expand Down

0 comments on commit d4131a9

Please sign in to comment.