Thanks for the work. I see, you pass goods
inside each user class as a parameter. It’s understandable but does not look good because of:
- it’s a personal storage. Maybe I’m oversimplified the sample case when wrote goods as Integer.
- with already a lot of constructor parameters (like there also can be
personnel
or other shareable parameters) it adds extra. And goods can be not a single parameter inside Consumer and Producer.
I’m curious, why didn’t implement the storage in a subclass? It could be inconvenient to pass it through the many classes like it’s something detachable. Let’s pretend it’s a map of many goods there and each building has its own storage. Maybe you need to pass the whole Building
as a parameter.
Also I didn’t understand how did you implement
fun loadGoods(goods: Int) {
...
println("$name loaded $goods goods")
}
if Consumer
doesn’t inherit Building
. And we remember, name
represents a lot of parameters (like workHours(), personnel
etc.). The goal is - these building vars and methods can be used everywhere in the class.
class SimpleConsumer(protected val store: GoodsStore) : Consumer {
Looks possible to use Kotlin syntax and remove extra line with protected
You got rid off the type
as unnecessary. Yeah, in original it should switch the goods that will be produced, but it’s a minor case. And TypedProducer
is not a producer here.
I’ll try to find something to use in my code. Currently I see, it’s possible to not to implement SimpleProducer / SimpleConsumer
as a constructor variable. And you can inherit your delegates from other classes. But I can’t pass the whole building as a delegate parameter because 'this' is not defined in this context
, so it makes it less simple.