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?

  • @[email protected]
    link
    fedilink
    English
    17 hours ago

    The models in my project have several ways of doing it. On the server side, there’s a function that accepts data from the DB, and a function that accepts data from the frontend. Same with serializing. One function to serialize the data for the DB and one to serialize for the frontend. On the frontend, it’s simpler, since it only sends/receives to/from the server.

    That’s mostly abstracted away in a top level class called “Entity”. It’s only if you need to do something special that you’d reimplement those functions. My data abstraction library is open source at https://nymph.io/ if you wanna check it out. It’s what runs my email service, https://port87.com/.