aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Prototype Java Design Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Prototype Java Design Pattern" Watch "Prototype Java Design Pattern" New topic
Author

Prototype Java Design Pattern

Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
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: 6920
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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
jQuery in Action, 2nd edition
 
subject: Prototype Java Design Pattern