✅ Immutable object with mutable clone
I have a class EntityData which is full of fields that need to be read only (everything public get, private set).
I want to be able to make a different object that is a mutable clone, which behaves like EntityData in every way except every property is public.
During runtime, I will have multiple instances of a class (EntityDataHolder) which will get fed an immutable original EntityData, and then make a mutable clone so that this particular instance of EntityDataHolder can modify it freely.
I will later add more fields to EntityData, and I don’t want its definition and its clone’s definition to get messed up/misaligned (ie I want to avoid writing every field 4 times to make one on the original, clone, and clone-copying class all match up).
What is a clean way to do this?
I want to be able to make a different object that is a mutable clone, which behaves like EntityData in every way except every property is public.
During runtime, I will have multiple instances of a class (EntityDataHolder) which will get fed an immutable original EntityData, and then make a mutable clone so that this particular instance of EntityDataHolder can modify it freely.
I will later add more fields to EntityData, and I don’t want its definition and its clone’s definition to get messed up/misaligned (ie I want to avoid writing every field 4 times to make one on the original, clone, and clone-copying class all match up).
What is a clean way to do this?