Skip to content

Commit

Permalink
Merge pull request #421 from HoussemNasri/bridge-pattern-in-kotlin
Browse files Browse the repository at this point in the history
Add the bridge design pattern in Kotlin
  • Loading branch information
ZoranPandovski authored Oct 26, 2021
2 parents 21dc0e5 + 114e189 commit 113c905
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Structural/Bridge/kotlin/BridgePattern.kt
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()
}

0 comments on commit 113c905

Please sign in to comment.