-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #421 from HoussemNasri/bridge-pattern-in-kotlin
Add the bridge design pattern in Kotlin
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
interface Color { | ||
fun getColor() | ||
} | ||
|
||
class Yellow: Color { | ||
override fun getColor() { | ||
println("Yellow") | ||
} | ||
} | ||
|
||
class Red: Color { | ||
override fun getColor() { | ||
println("Red") | ||
} | ||
} | ||
|
||
interface House { | ||
val color: Color | ||
fun show() | ||
} | ||
|
||
class WoodHouse(override val color: Color): House { | ||
override fun show() { | ||
print("The wood house color is ") | ||
color.getColor() | ||
} | ||
} | ||
|
||
class RockHouse(override val color: Color): House { | ||
override fun show() { | ||
print("The rock house color is ") | ||
color.getColor() | ||
} | ||
} | ||
|
||
fun main() { | ||
val yellowWoodHouse = WoodHouse(color = Yellow()) | ||
yellowWoodHouse.show() | ||
val yellowRockHouse = RockHouse(color = Yellow()) | ||
yellowRockHouse.show() | ||
val redWoodHouse = WoodHouse(color = Red()) | ||
redWoodHouse.show() | ||
val redRockHouse = RockHouse(color = Red()) | ||
redRockHouse.show() | ||
} |