Look at the inheritance-based implementation of the RedCircle class and use the composition approach to implement the RedCircleComposition class.
Interface composition
Compositional mystery of Red Circle
Report a typo
Write a program in Kotlin
interface Color {
fun getColorCode(): String
}
interface Shape {
fun getShape(): String
fun countAngles(): Int
}
class RedCircle : Color, Shape {
override fun getColorCode(): String = "FF0000"
override fun getShape(): String = "Circle"
override fun countAngles(): Int = 0
}
object Red : Color {
override fun getColorCode(): String = "FF0000"
}
object Circle : Shape {
override fun getShape(): String = "Circle"
override fun countAngles(): Int = 0
}
// Do not change the code above.
// Change only *line* below.
class RedCircleComposition : // ?
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.