I start to learn design-patterns. I understand that prototype is for making an exact copy of an object I already have and Flyweight is for making similar objects.
I've programmed 2D platformer game like Mario (in Java). There are a lot of enemies which are the same the only difference is their position [x,y]
. There are also walls which are built from a huge number of rectangles and again the only difference is their position [x,y]
.
Is it wise to use some of these design patterns in this particular situation? Should I use prototype to clone objects via cloneable and then set [x,y]
?
Is it better to use flyweight - when I need new object I just return them from my hashmap and then set [x,y]?
In both scenarios I avoid using new operator but I am not sure which one to use.