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?

  • packadal@beehaw.org
    link
    fedilink
    arrow-up
    2
    ·
    13 hours ago

    You should group your source files by domain, then by feature, e.g. ‘src/foo/model’ and ‘src/foo/exports’.

    Is serialization/deserialization the only aim of these structures ? If not, that code should definitely be separated, so as to evolve separately from the structure itself.

    If it is the only aim, the code should also be separated, so you can change your serialization type (e.g. from JSON to XML) without impacting the model.

    Also you might need another export for compatibility with another software, and you don’t want your model file to grow with the 10 formats you support.