Question Details

No question body available.

Tags

data-structures clean-architecture polymorphism

Answers (1)

March 23, 2025 Score: 5 Rep: 4,896 Quality: Medium Completeness: 50%

In my experience (mostly various enterprise IDEs), the worst thing one can do is to use direct reflection based persistence of Entities (reflection over DAL objects is fine) like ORM or serialization built into a language.

Another common error is to allow model to convert itself into serialization-friendly format.

Both of these approaches leak persistence concern into model, preventing backward compatible model updates.

Anything else goes:

  • an adapter for each type that converts data in persistence friendly form
  • a direct storage specific conversion for each entity

Class hierarchy of Entities does not have any effect on serialization decisions, in a sense that serialization should adapt to model hierarchy, not the other way around, and if model introduces a new hierarchy root, serialization will have to support that too.

All valid approaches require explicit handling of each Entity in persistence layer.

So to answer your question - if you want to preserve backward compatibility with old save files and maintain your project for years, you have to explicitly do Entity specific handling in DAL, even if you don't create a serializable objects explicitly.

However, if your game is short and does not need to survive updates, or you are not going to support it after release, why do you even need a Clean Architecture? Just use any dumb serialization framework and forget about it.