I have in mind two options:

  • Code in the class being saved/loaded. The flows for each entity/model are in the same place, so it’s easy to just have one file open to see all the functionalities of that class, but this means having more code in a single file.
  • Code in a dedicated class (like a factory)
    This makes each file smaller, but spreads flows of a single model into different parts of the repo, also because I’m thinking of having a directory /src/models and another like /src/export (or serialize)

What do you guys think?
What’s your preferred way to organize the save and load flows?

  • tocano
    link
    fedilink
    arrow-up
    3
    ·
    6 hours ago

    Usually my models only store data, meaning the files that contain them don’t have much code. The decision also depends on the tools you are using and who you are working with. I would fallback to the rule of separation of responsabilities and write a new class for the purpuse of serializing the model (which could and should also serialize similiar models). This way is universal in any language and can easily be understood by future you and colleages.