Created
January 22, 2023 16:15
-
-
Save alibahaaa/b31b398646d902b31d68671da0d6229c to your computer and use it in GitHub Desktop.
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
interface Component { | |
fun operation() | |
} | |
class Leaf : Component { | |
override fun operation() { | |
// implementation | |
} | |
} | |
class Composite : Component { | |
private val children = mutableListOf<Component>() | |
override fun operation() { | |
for (child in children) { | |
child.operation() | |
} | |
} | |
fun add(component: Component) { | |
children.add(component) | |
} | |
fun remove(component: Component) { | |
children.remove(component) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment