Returning a new tile based on tile in an array.

So for my game I am using a tile based system , how would I implement it so that instead of having a switch statement with each tile in it that is returned based on the id, that I use a system that gets a new object based on the object in an array . If that was a bit iffy to understand , if I had an array containing two objects , A and B , I then want to make a new object that I can use but wont be the same as A , like creating a new A object but only doing it from the array.

Cancel that , found it within getClass();
Ok scratch that , its a subclass hence its returning a failed instantiation error. ill try clone

I guess you could clone the object with clone();

I would use a factory.
I do not like the clone method. I prefer a copy constructor.

ClaasJG

Clone currently works , albeit inefficiently. Would you mind giving an example of using a factory?

Well, i guess i wont be able to do it today but i will edit this post with an example as soon as i can. But a factory would simple be stored for every id and would create a tile for the given id.

ClaasJG

Thats what I originally had however it then makes it difficult to add new tiles and also a hassle for developers if they were then to use it.