Changes

Jump to: navigation, search

Prototype

774 bytes added, 23:03, 17 March 2007
Sample code
'''Java Sample:'''
Prototype pattern in java is implemented using the Clonable interface which provides the clone() method. Cloneable is an empty interface. It simply acts as a tag to indicate that the implementing classes need their instances to support clonning.
Subclasses must implement the Clonable interface and then override the clone() method and call the super classes clone method in the implementation of overridden clone method using super.clone() statement.If you don't implement Cloneable, the super.clone() implementation will throw a CloneNotSupportedException.
 
The following is the implementation of Cookie class in apache tomcat server. This class makes use of prototype pattern and Clonable interface to create clones of cookie object.
 
apache-tomcat-6.0.10 - Cookie.java
<pre>
1
edit

Navigation menu