Skip to content

Instantly share code, notes, and snippets.

@alibahaaa
Created January 22, 2023 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alibahaaa/b31b398646d902b31d68671da0d6229c to your computer and use it in GitHub Desktop.
Save alibahaaa/b31b398646d902b31d68671da0d6229c to your computer and use it in GitHub Desktop.
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