mardi 14 décembre 2021

Where should the code processing the state of the object be?

I have a class as follows:

data class ProductState(
  val id: Int,
  val products: MutableMap<Int, MutableSet<Int>> = mutableMapOf(),
  val customerTopics: Topic = Topic()
)

It is basically a data class.
Now I have a function that among other things, processes the products and customerTopics and creates some output based on the processing.
But it seems to me that it is not a good idea to have the logic in the function.
My question is:
Do we create methods inside the data class for the processing of the object'state? If so would it be some companion object? Or is there some other design pattern that deals with this better?

Aucun commentaire:

Enregistrer un commentaire