We have a class that is more like a template (with lot of properties and overridden methods). I need to make many objects of that class type. Can I use clone() to create objects with specific settings if I have one object created? I know I need to override the Clone method. Is the performance going to take a hit by using Clone()?
views:
27answers:
2
A:
Cloning an object as a way of creating new objects is not necessarily the cleanest method of creating objects. It is better to use constructors or factory methods (which call constructors).
You may be interested in using a factory or builder pattern. Or if you are worried about the memory overhead of a large number of similar objects, take a look at the flyweight pattern.
Avi
2010-03-25 14:47:14
A:
Clone in itself is not bad practice, its generally shallow. BUt i think you want to be using a pattern. More than likely Prototype Pattern is your solution.
The clone you are doing is really a cookie cutting of your prototype.
The link i sent is from DO factory and has code samples for you.
Nix
2010-03-25 14:59:50