This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prototype Java Design Pattern
 
Similar Threads
Clone V/s Creating a new Instance
some doubts in core java
why clone() ?
Question on Prototype pattern
clone() or lack thereof