Valentin Metz
08/29/2020, 7:08 PMMark Spindler
08/29/2020, 8:17 PMArray
or could it be a MutableList
? Are you sure you want to do things this way? It sounds weird to me to have an array of 1000 functions rather than a function that calls the other functions more directly or a function that combines them.Valentin Metz
08/30/2020, 1:32 AMMichael de Kaste
08/31/2020, 7:29 AMMichael de Kaste
08/31/2020, 7:36 AMValentin Metz
08/31/2020, 7:56 AMMichael de Kaste
08/31/2020, 9:28 AMsealed class EulerExample1{
abstract fun solve(params: Array<String>)
companion object{
val classMap = EulerExample1::class
.sealedSubclasses
.associateBy({it.simpleName},{it.objectInstance})
}
}
object Problem1Example1 : EulerExample1() {
override fun solve(params: Array<String>) {
println("solving problem 1")
}
}
object Problem2Example1 : EulerExample1() {
override fun solve(params: Array<String>) {
println("solving problem 2")
}
}
with fun main:
fun main(params: Array<String>){
EulerExample1.classMap["Problem1Example1"]?.solve(params)
EulerExample1.classMap["Problem2Example1"]?.solve(params)
}
Michael de Kaste
08/31/2020, 9:32 AMfun main(params: Array<String>){
EulerExample2.classMap["Problem1"]?.solve(params)
EulerExample2.classMap["Problem2"]?.solve(params)
}
sealed class EulerExample2 : IEulerExample2{
companion object{
val classMap = EulerExample2::class
.sealedSubclasses
.associateBy({it.simpleName},{it.objectInstance})
}
object Problem1 : EulerExample2(), IEulerExample2 by P1
object Problem2 : EulerExample2(), IEulerExample2 by P2
}
interface IEulerExample2{
fun solve(params: Array<String>)
}
object P1 : IEulerExample2 {
override fun solve(params: Array<String>) {
println("solving problem 1")
}
}
object P2 : IEulerExample2 {
override fun solve(params: Array<String>) {
println("solving problem 2")
}
}
P1 and P2 can be in seperate files so you can work on them individuallyMichael de Kaste
08/31/2020, 9:36 AMMichael de Kaste
08/31/2020, 9:36 AMValentin Metz
08/31/2020, 11:09 AMMichael de Kaste
09/01/2020, 12:08 PM