Let’s say a case class models a game state. And whether a game state is won/lost can be computed by a method, from some fields on a given state instance. This method to compute win/loss can be either defined inside the case class itself, or outside it, eg in its companion object. This changes the api experience correspondingly,
stateInstance.isWon in the former case (concise) and
State.isWon(stateInstance) in the latter (verbose).
What implications does this have on app’s performance/memory-footprint?
If the method is defined inside the case class, does instantiation of multiple case classes imply redundant memory footprint because, the methods defined inside, occupy their space as well, in all the case class instances? Or, on the contrary, does the compiler eliminate this duplication?
Or, if the method is defined on the companion object, which is a singleton, does this mean that the aforementioned redundancy is eliminated, because those methods are present only in one single space in the app’s runtime?