Created
January 22, 2023 16:20
-
-
Save alibahaaa/1102dd8fda17f09736da38430d634446 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 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