true, if you just want a factory method to be responsible for instantiation, make the constructor private and implement the method in the companion object - whether you implement
invoke
or give it a more descriptive name is up to you
j
Jakub Pi
04/22/2020, 9:54 PM
You'll need to be clearer about your objectives. Is there only one instance of Dog for the whole of your program? That's a singleton. Are you trying to potentially return a subclass of Dog? That's an abstract factory. Is there a network request that is serializing your object? You may need to dig down into things like readResolve.. Not sure if that one is applicable to Kotlin though.