Skip to content

Instantly share code, notes, and snippets.

@alibahaaa
Created January 22, 2023 16:20
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/1102dd8fda17f09736da38430d634446 to your computer and use it in GitHub Desktop.
Save alibahaaa/1102dd8fda17f09736da38430d634446 to your computer and use it in GitHub Desktop.
interface ViewComponent {
fun draw()
}
class TextView : ViewComponent {
override fun draw() {
// Draw text view on screen
}
}
class ImageView : ViewComponent {
override fun draw() {
// Draw image view on screen
}
}
class LinearLayout : ViewComponent {
private val viewComponents = mutableListOf<ViewComponent>()
fun addView(view: ViewComponent) {
viewComponents.add(view)
}
fun removeView(view: ViewComponent) {
viewComponents.remove(view)
}
override fun draw() {
for (view in viewComponents) {
view.draw()
}
}
}
val linearLayout = LinearLayout()
val textView = TextView()
val imageView = ImageView()
linearLayout.addView(textView)
linearLayout.addView(imageView)
linearLayout.draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment