Essentially I just want a public class but with pr...
# announcements
j
Essentially I just want a public class but with protected constructor (I understand this isn't possible in Kotlin) so that the only way to construct it is through the factory
c
why would you think that it is impossible?
open class PublicClassProtectedConstructor protected constructor(/*...*/)
in your ☕ example you missed that
Factory
extends
PublicClassProtectedConstructor
to be able to see the constructor 🙂
f
j
The issue is that I have multiple different constructors within the factory with vastly different parameters. I'm building midi byte sequences; sometimes there are no parameters; sometimes I need a device ID; sometimes it takes a volume and patch number...
f
you can still have multiple constructors
did your factory methods just get the arguments and just send them to a protected constructor?
j
The factory methods take the arguments and place them into a sequence of bytes. Often logic is involved
Then that is sent to the constructor
f
Copy code
class PublicClassProtectedConstructor private constructor(private val bytes: ByteArray) {
    companion object Factory {
        fun factory1(deviceId: String): PublicClassProtectedConstructor {
            val bytes = ByteArray(0) // Setup however
            return PublicClassProtectedConstructor(bytes)
        }

        fun factory2(volume: Int, patch: Int): PublicClassProtectedConstructor {
            val bytes = ByteArray(0) // Setup however
            return PublicClassProtectedConstructor(bytes)
        }
    }
}