Hi all,
I have a question about dealling with heritage with kotlin.
In my Use case,
In my domain I’m dealling with events. This is my model
interface IDomainEvent
data class WarriorCreated(val content: String): IDomainEvent
data class WarriorDeleted(val content: String = ""): IDomainEvent
In my app, when the user command to delete a ‘warrior’, a WarriorDeleted is created, publish and apply :
fun delete(publisher: IEventPublisher) {
if (!projection.isDeleted()) {
val evt = WarriorDeleted()
publisher.publish(evt)
projection.apply(evt)
}
}
I would like to create a more generic method like to publish and apply an event
like this for example
fun delete(publisher: IEventPublisher) {
if (!projection.isDeleted()) {
publishAndApplyEvent(publisher, WarriorDeleted())
}
}
fun publishAndApplyEvent(publisher: IEventPublisher, evt: IDomainEvent) {
publisher.publish(evt)
projection.apply(evt)
}
And I created these 2 methods apply :
fun apply(evt: WarriorDeleted) {
deleted = true
}
fun apply(evt: WarriorCreated) {
}
In this case I have a compilation error : kotlin can’t find the good method appy() depending of the of IDomainEvent.
Is there an easy way for kotlin to find the good method ?
Thanks,