To be more specific, I need to organize this kind of interactions (simplified):
class SteelFactory() : Building(name = "Steel Factory"), Producer, Consumer {}
class CopperFactory() : Building(name = "Copper Factory"), Producer, Consumer {}
class PowerPlant() : Building(name = "Power Plant"), Consumer {}
class Mine(private val type: Int) : Building, TypedProducer {
fun produceCoal() {
goodsOut++
}
fun producIron() {
goodsOut += 2
}
}
interface Producer {
var goodsOut: Int?
protected set
fun produce() {
if (goodsIn != null)
goodsIn--
goodsOut++
}
fun unloadGoods(goods: Int) {
goodsOut -= goods
}
}
interface Consumer {
var goodsIn: Int?
protected set
fun loadGoods(goods: Int) {
goodsIn += goods
println("$name loaded $goods goods")
}
}
interface TypedProducer : Producer {
var type: Int
fun setType(value: Int) {
type = value
when (type) {
1 -> produceCoal()
2 -> produceIron()
}
println("$name switched to $type")
}
fun produceCoal()
fun produceIron()
}
abstract class Building(val name: String) {}
Could you help me?