Clone Object

I have a dictionary of objects Dictionary<String, Module> that I want to use as a template in order to create new objects out of them. Specifically I have a Tile object which has a Module object property.
The idea is to have for every tile different modules assign on them (not as instances but as unique objects), because I want in later stage to be able and mutate the Module of each Tile in a certain way (let’s say to just change its color).
So far the only work around I found is to split the Module object and Create a new before pass it in my Tile object.
How it could be done otherwise ?

Not sure what exactly the problem but sounds like you need an interface, like IModule, so then you’ll be able to connect different objects to same pin…

There is also a template selector pattern, usually it is multiple templates, like template1 template2, and a switch with cast like if object of type1 return template1… if that makes sense

thx @antokhio but it is not the case. I am constructing a list (dictionary in my case) of objects which I want to use as templates for other objects which have the same exact characteristics and a certain initial state (same as the template objects in the dictionary). Does it make sense now?

This is the Prototype Pattern : Prototype

@lecloneur yes, exactly, this is it. Any ideas how to approach this, beside splitting a d creating the objects from scratch :)

The Module object you want to Clone should actually have the function to create a copy of itself. So you don’t need to split but just create and return that object.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.