- Hands-On Design Patterns with Kotlin
- Alexey Soshin
- 61字
- 2021-06-25 20:49:29
Abstract Factory in action
Our strategy game will consist of buildings and units. Let's start with declaring what all buildings share:
interface Building<in UnitType, out ProducedUnit>
where UnitType : Enum<*>, ProducedUnit : Unit {
fun build(type: UnitType) : ProducedUnit
}
All buildings should implement the build() function. Here we see generics in Kotlin for the first time, so let's discuss them a bit.