How do I handle polymorphic domain models in a Clean Architecture data access layer?
Let's say I'm making a space 4X game (because I am!) and I have an ISpaceObject interface in my domain layer, with a number of classes such as Ship, Starbase, Planet, Wormhole, etc. implementing it. I want to apply Clean Architecture and create a data acess layer. How can I do this for these polymorphic types? Would I need to mirror every single one of them in the data access layer (ShipData, etc.) and when I go to serialize a Ship I'd need to have a special case for that where I create a ShipData with the actual data from the Ship that needs to be saved? That seems a bit brittle as if I add a new class implementing ISpaceObject, I'd get a runtime exception if I never set up a special case for it in the DAL. Surely there's a better way? (But even this would be better than what I'm doing now, which is dumping the domain models into a catchall serializer that can handle just about anything...)

Let's say I'm making a space 4X game (because I am!) and I have an ISpaceObject
interface in my domain layer, with a number of classes such as Ship
, Starbase
, Planet
, Wormhole
, etc. implementing it. I want to apply Clean Architecture and create a data acess layer. How can I do this for these polymorphic types? Would I need to mirror every single one of them in the data access layer (ShipData
, etc.) and when I go to serialize a Ship
I'd need to have a special case for that where I create a ShipData
with the actual data from the Ship
that needs to be saved? That seems a bit brittle as if I add a new class implementing ISpaceObject
, I'd get a runtime exception if I never set up a special case for it in the DAL. Surely there's a better way? (But even this would be better than what I'm doing now, which is dumping the domain models into a catchall serializer that can handle just about anything...)