Hi All, I just started reading the Java Design pattern & referred the following url for understanding the Prototype Design pattern. (http://www.fluffycat.com/java/JavaNotes-GoFPrototype.html) But I am not sure whether will we use this pattern for the given usage(i.e for creating soupspoons, saladspoons in that example. I think we can directly instantiate the soupspoons and saladspoons). Can you please clarify the prototype usage. My Observation for prototype pattern usage is: If i want to have a copy of the instance then i can use the prototype pattern. For that i have to get the clone of object by implementing Clonable interface and calling the clone method then serialize & deserialize the result object to get the copy of the given instance. Am I right? What is the advantage of doing so? Thanks & Regards, M.S.Raman.
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6913
posted
0
YOu wrote: For that i have to get the clone of object by implementing Clonable interface and calling the clone method then serialize & deserialize the result object to get the copy of the given instance. Am I right? I don't think you need the serialization step. Just calling "clone" should be enough. There is some discussion of the "prototype" pattern in this old thread which may help clear things up a bit.