https://kotlinlang.org logo
#announcements
Title
# announcements
r

Ruckus

05/05/2017, 3:50 PM
The children of
EntityGroup
should extend from
EntityBase<T>
so I can have both `Entity`s and `EntityGroup`s in there.
m

mg6maciej

05/05/2017, 4:00 PM
r

Ruckus

05/05/2017, 4:05 PM
I was using something like that before, but I actually have several of these patterns that all come from the same
BaseClass
and I was hoping for more type safety. (I don't want the children of
EntityGroup
to take any
Showable
, I want to restrict it to `EntityBase`s.) Similar with
ItemGroup
and other
[Type]Group
classes.
m

mg6maciej

05/05/2017, 4:08 PM
I was suspecting that could be the case. Then use delegation instead of inheritance, put all group related stuff in a separate class and from each and every group you have, delegate to that object.
Delegation should remove a lot of boilerplate from your code.
r

Ruckus

05/05/2017, 4:08 PM
Indeed. I'll try that. Thanks!
m

mg6maciej

05/05/2017, 4:09 PM
And still you would not have to do anything weird like using
Nothing
.
👍 1
class EntityGroup : EntityBase, Group<EntityBase> by GroupImpl()
or something like this.
3 Views