I new to Kotlin and attempting to "get to grips" with it
I have set myself an exercise where I wish to define a group of related class pairs with the following restrictions
The following Pseudo code illustrates my desired design:-
I wish to declare a function that accepts an input and produces an Output as shown here...
fun process(input : Input) : Output
I will declare generic interfaces as follows:-
interface Input<I> {
val input: I
}
interface Output<O> {
val output: O
}
I wish to declare concrete classes for both Input & Output above:-
data class CustomInput_1(override val input: CustomData_1) : Input<CustomData_1>
data class CustomOutput_1(override val output: CustomData_2) : Output<CustomData_2>
data class CustomInput_2(override val input: CustomData_3) : Input<CustomData_3>
data class CustomOutput_2(override val output: CustomData_4) : Output<CustomData_4>
data class CustomInput_3(override val input: CustomData_5) : Input<CustomData_5>
data class CustomOutput_3(override val output: CustomData_6) : Output<CustomData_6>
...
...
...
data class CustomInput_N(override val input: CustomData_X) : Input<CustomData_X>
data class CustomOutput_N(override val output: CustomData_Y) : Output<CustomData_Y>
using these above example classes as reference I wish to have the following restrictions in place
Each Input can only produce a certain Output as follows:-
when CustomInput_1 is passed to the process function it can only produce (return) CustomOutput_1
when CustomInput_2 is passed to the process function it can only produce (return) CustomOutput_2
...
...
...
when CustomInput_N is passed to the process function it can only produce (return) CustomOutput_N
How can I employ Kotlin to implement these relationships? and not have these rules "broken" by users of my classes?
In addition is it possible to enforce that CustomInput_1 is only ever passed type CustomData_1, CustomOutput_1 is only ever passed type CustomData_2 etc?