{"id":44765,"date":"2015-09-30T06:37:23","date_gmt":"2015-09-30T03:37:23","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=44765"},"modified":"2023-12-07T11:20:36","modified_gmt":"2023-12-07T09:20:36","slug":"prototype-design-pattern","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html","title":{"rendered":"Prototype Design Pattern Example"},"content":{"rendered":"<p><em>This article is part of our Academy Course titled <a href=\"http:\/\/www.javacodegeeks.com\/2015\/09\/java-design-patterns\/\">Java Design Patterns<\/a>.<\/em><\/p>\n<p>In this course you will delve into a vast number of Design Patterns and see how those are implemented and utilized in Java. You will understand the reasons why patterns are so important and learn when and how to apply each one of them. Check it out <a href=\"http:\/\/www.javacodegeeks.com\/2015\/09\/java-design-patterns\/\">here<\/a>!<\/p>\n<div class=\"toc\">\n<h4>Table Of Contents<\/h4>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#What is the Prototype Design Pattern\">2. What is the Prototype Design Pattern<\/a><\/dt>\n<dt><a href=\"#Solution to the Problem\">3. Solution to the Problem<\/a><\/dt>\n<dt><a href=\"#When to use the Prototype Design Pattern\">4. When to use the Prototype Design Pattern<\/a><\/dt>\n<dt><a href=\"#Prototype Pattern in JDK\">5. Prototype Pattern in JDK<\/a><\/dt>\n<dt><a href=\"#Download the Source Code\">6. Download the Source Code<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"introduction\"><\/a>1. Introduction<\/h2>\n<p>In Object Oriented Programming, you need objects to work with; objects interact with each other to get the job done. But sometimes, creating a heavy object could become costly, and if your application needs too many of that kind of objects (containing almost similar properties), it might create some performance issues.<\/p>\n<p>Let us consider a scenario where an application requires some access control. The features of the applications can be used by the users according to the access rights provided to them. For example, some users have access to the reports generated by the application, while some don\u2019t. Some of them even can modify the reports, while some can only read it. Some users also have administrative rights to add or even remove other users.<\/p>\n<p>Every user object has an access control object, which is used to provide or restrict the controls of the application. This access control object is a bulky, heavy object and its creation is very costly since it requires data to be fetched from some external resources, like databases or some property files etc.<\/p>\n<p>We also cannot share the same access control object with users of the same level, because the rights can be changed at runtime by the administrator and a different user with the same level could have a different access control. One user object should have one access control object.<\/p>\n<p>We can use the Prototype Design Pattern to resolve this problem by creating the access control objects on all levels at once, and then provide a copy of the object to the user whenever required. In this case, data fetching from the external resources happens only once. Next time, the access control object is created by copying the existing one. The access control object is not created from scratch every time the request is sent; this approach will certainly reduce object creation time.<\/p>\n<p>Before digging into the solution, let us know more about the Prototype Design Pattern.<\/p>\n<h2><a name=\"What is the Prototype Design Pattern\"><\/a>2. What is the Prototype Design Pattern<\/h2>\n<p>The Prototype design pattern is used to specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.<\/p>\n<p>The concept is to copy an existing object rather than creating a new instance from scratch, something that may include costly operations. The existing object acts as a prototype and contains the state of the object. The newly copied object may change same properties only if required. This approach saves costly resources and time, especially when the object creation is a heavy process.<\/p>\n<p>In Java, there are certain ways to copy an object in order to create a new one. One way to achieve this is using the <code>Cloneable<\/code> interface. Java provides the <code>clone<\/code> method, which an object inherits from the <code>Object<\/code> class. You need to implement the <code>Cloneable<\/code> interface and override this <code>clone<\/code>method according to your needs.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><figure id=\"attachment_7137\" aria-describedby=\"caption-attachment-7137\" style=\"width: 456px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/PrototypePatternclass_diagram_11.jpg\"><img decoding=\"async\" class=\"wp-image-7137 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/PrototypePatternclass_diagram_11.jpg\" alt=\"class_diagram_1\" width=\"456\" height=\"183\" \/><\/a><figcaption id=\"caption-attachment-7137\" class=\"wp-caption-text\">Figure 1<\/figcaption><\/figure><\/p>\n<p><strong>Prototype<\/strong><\/p>\n<ul>\n<li>Declares an interface for cloning itself.<\/li>\n<\/ul>\n<p><strong>ConcretePrototype<\/strong><\/p>\n<ul>\n<li>Implements an operation for cloning itself.<\/li>\n<\/ul>\n<p><strong>Client<\/strong><\/p>\n<ul>\n<li>Creates a new object by asking a prototype to clone itself.<\/li>\n<\/ul>\n<p>Prototypes let you incorporate a new concrete product class into a system simply by registering a prototypical instance with the client.<\/p>\n<h2><a name=\"Solution to the Problem\"><\/a>3. Solution to the Problem<\/h2>\n<p>In this solution, we will use the clone method to solve the above problem.<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.patterns.prototypepattern;\n\npublic interface Prototype extends Cloneable {\n\n\tpublic AccessControl clone() throws CloneNotSupportedException;\n\n}<\/pre>\n<p>The above interface extends the <code>Cloneable<\/code> interface and contains a method <code>clone<\/code>. This interface is implemented by classes which want to create a prototype object.<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.patterns.prototypepattern;\n\npublic class AccessControl implements Prototype{\n\n\tprivate final String controlLevel;\n\tprivate String access;\n\n\tpublic AccessControl(String controlLevel,String access){\n\t\tthis.controlLevel = controlLevel;\n\t\tthis.access = access;\n\t}\n\n\t@Override\n\tpublic AccessControl clone(){\n\t\ttry {\n\t\t\treturn (AccessControl) super.clone();\n\t\t} catch (CloneNotSupportedException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn null;\n\t}\n\n\tpublic String getControlLevel(){\n\t\treturn controlLevel;\n\t}\n\n\tpublic String getAccess() {\n\t\treturn access;\n\t}\n\n\tpublic void setAccess(String access) {\n\t\tthis.access = access;\n\t}\n\n}<\/pre>\n<p>The <code>AccessControl<\/code> class implements the <code>Prototype<\/code> interface and overrides the <code>clone<\/code> method. The method calls the <code>clone<\/code> method of the super class and returns the object after down-casting it to the <code>AccessControl<\/code> type. The <code>clone<\/code> method throws <code>CloneNotSupportedException<\/code> which is caught within the method itself.<\/p>\n<p>The class also contains two properties; the <code>controlLevel<\/code> is used to specific the level of control this object contains. The level depends upon the type of user going to use it, for example, USER, ADMIN, MANAGER etc.<\/p>\n<p>The other property is the <code>access<\/code>; it contains the access right for the user. Please note that, for simplicity, we have used access as a <code>String<\/code> type attribute. This could be of type <code>Map<\/code> which can contain key value pairs of long access rights assigned to the user.<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.patterns.prototypepattern;\n\npublic class User {\n\n\tprivate String userName;\n\tprivate String level;\n\tprivate AccessControl accessControl;\n\n\tpublic User(String userName,String level, AccessControl accessControl){\n\t\tthis.userName = userName;\n\t\tthis.level = level;\n\t\tthis.accessControl = accessControl;\n\t}\n\n\tpublic String getUserName() {\n\t\treturn userName;\n\t}\n\tpublic void setUserName(String userName) {\n\t\tthis.userName = userName;\n\t}\n\tpublic String getLevel() {\n\t\treturn level;\n\t}\n\tpublic void setLevel(String level) {\n\t\tthis.level = level;\n\t}\n\tpublic AccessControl getAccessControl() {\n\t\treturn accessControl;\n\t}\n\tpublic void setAccessControl(AccessControl accessControl) {\n\t\tthis.accessControl = accessControl;\n\t}\n\n\t@Override\n\tpublic String toString(){\n\t\treturn \"Name: \"+userName+\", Level: \"+level+\", Access Control Level:\"+accessControl.getControlLevel()+\", Access: \"+accessControl.getAccess();\n\t}\n\n}<\/pre>\n<p>The <code>User<\/code> class has a <code>userName<\/code>, <code>level<\/code> and a reference to the <code>AccessControl<\/code> assigned to it.<br \/>\n[ulp id=&#8217;7eyRwVlMDyxg6Ptw&#8217;]<br \/>\n&nbsp;<br \/>\nWe have used an <code>AccessControlProvider<\/code> class that creates and stores the possible <code>AccessControl<\/code> objects in advance. And when the there\u2019s a request to an <code>AccessControl<\/code> object, it returns a new object created by copying the stored prototypes.<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.patterns.prototypepattern;\n\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class AccessControlProvider {\n\n\tprivate static Map&lt;String, AccessControl&gt;map = new HashMap&lt;String, AccessControl&gt;();\n\n\tstatic{\n\n\t\tSystem.out.println(\"Fetching data from external resources and creating access control objects...\");\n\t\tmap.put(\"USER\", new AccessControl(\"USER\",\"DO_WORK\"));\n\t\tmap.put(\"ADMIN\", new AccessControl(\"ADMIN\",\"ADD\/REMOVE USERS\"));\n\t\tmap.put(\"MANAGER\", new AccessControl(\"MANAGER\",\"GENERATE\/READ REPORTS\"));\n\t\tmap.put(\"VP\", new AccessControl(\"VP\",\"MODIFY REPORTS\"));\n\t}\n\n\tpublic static AccessControl getAccessControlObject(String controlLevel){\n\t\tAccessControl ac = null;\n\t\tac = map.get(controlLevel);\n\t\tif(ac!=null){\n\t\t\treturn ac.clone();\n\t\t}\n\t\treturn null;\n\t}\n}<\/pre>\n<p>The <code>getAccessControlObject<\/code> method fetches a stored prototype object according to the <code>controlLevel<\/code> passed to it, from the map and returns a newly created cloned object to the client code.<\/p>\n<p>Now, let\u2019s test the code.<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.patterns.prototypepattern;\n\npublic class TestPrototypePattern {\n\n\tpublic static void main(String[] args) {\n\t\tAccessControl userAccessControl = AccessControlProvider.getAccessControlObject(\"USER\");\n\t\tUser user = new User(\"User A\", \"USER Level\", userAccessControl);\n\n\t\tSystem.out.println(\"************************************\");\n\t\tSystem.out.println(user);\n\n\t\tuserAccessControl = AccessControlProvider.getAccessControlObject(\"USER\");\n\t\tuser = new User(\"User B\", \"USER Level\", userAccessControl);\n\t\tSystem.out.println(\"Changing access control of: \"+user.getUserName());\n\t\tuser.getAccessControl().setAccess(\"READ REPORTS\");\n\t\tSystem.out.println(user);\n\n\t\tSystem.out.println(\"************************************\");\n\n\t\tAccessControl managerAccessControl = AccessControlProvider.getAccessControlObject(\"MANAGER\");\n\t\tuser = new User(\"User C\", \"MANAGER Level\", managerAccessControl);\n\t\tSystem.out.println(user);\n\t}\n}<\/pre>\n<p>The above code will produce the following output:<\/p>\n<pre class=\"brush:bash\">Fetching data from external resources and creating access control objects...\n************************************\nName: User A, Level: USER Level, Access Control Level:USER, Access: DO_WORK\nChanging access of: User B\nName: User B, Level: USER Level, Access Control Level:USER, Access: READ REPORTS\n************************************\nName: User C, Level: MANAGER Level, Access Control Level:MANAGER, Access: GENERATE\/READ REPORTS<\/pre>\n<p>In the above code, we have created an <code>AccessControl<\/code> object at USER level and assigned it to User A. Then, again another <code>AccessControl<\/code> object to User B, but this time we have changed the access right of User B. And in the end, MANAGER level access control to User C.<\/p>\n<p>The <code>getAccessControlObject<\/code> is used to get the new copy of the <code>AccessControl<\/code> object, and this can be clearly seen when we change the access right for User B, the access right for User A is not changed (just print the User A object again). This confirms that the <code>clone<\/code> method is working fine, as it returns the new copy of the object not a reference which points to the same object.<\/p>\n<h2><a name=\"When to use the Prototype Design Pattern\"><\/a>4. When to use the Prototype Design Pattern<\/h2>\n<p>Use the Prototype pattern when a system should be independent of how its products are created, composed, and represented; and<\/p>\n<ul>\n<li>When the classes to instantiate are specified at run-time, for example, by dynamic loading; or<\/li>\n<li>To avoid building a class hierarchy of factories that parallels the class hierarchy of products; or<\/li>\n<li>When instances of a class can have one of only a few different combinations of state. It may be more convenient to install a corresponding number of prototypes and clone them rather than instantiating the class manually, each time with the appropriate state.<\/li>\n<\/ul>\n<h2><a name=\"Prototype Pattern in JDK\"><\/a>5. Prototype Pattern in JDK<\/h2>\n<ul>\n<li><code>java.lang.Object#clone()<\/code><\/li>\n<li><code>java.lang.Cloneable<\/code><\/li>\n<\/ul>\n<h2><a name=\"Download the Source Code\"><\/a>6. Download the Source Code<\/h2>\n<p>This was a lesson on the Prototype Design Pattern. You may download the source code here: <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/PrototypePattern-Project.zip\"><strong>PrototypePattern-Project<\/strong><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article is part of our Academy Course titled Java Design Patterns. In this course you will delve into a vast number of Design Patterns and see how those are implemented and utilized in Java. You will understand the reasons why patterns are so important and learn when and how to apply each one of &hellip;<\/p>\n","protected":false},"author":967,"featured_media":148,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[145],"class_list":["post-44765","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-design-patterns"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Prototype Design Pattern Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"This article is part of our Academy Course titled Java Design Patterns. In this course you will delve into a vast number of Design Patterns and see how\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Prototype Design Pattern Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"This article is part of our Academy Course titled Java Design Patterns. In this course you will delve into a vast number of Design Patterns and see how\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-09-30T03:37:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-07T09:20:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Rohit Joshi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit Joshi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html\"},\"author\":{\"name\":\"Rohit Joshi\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/ddd1b95af381c5042c09833e6a108e20\"},\"headline\":\"Prototype Design Pattern Example\",\"datePublished\":\"2015-09-30T03:37:23+00:00\",\"dateModified\":\"2023-12-07T09:20:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html\"},\"wordCount\":1115,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"keywords\":[\"Design Patterns\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html\",\"name\":\"Prototype Design Pattern Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"datePublished\":\"2015-09-30T03:37:23+00:00\",\"dateModified\":\"2023-12-07T09:20:36+00:00\",\"description\":\"This article is part of our Academy Course titled Java Design Patterns. In this course you will delve into a vast number of Design Patterns and see how\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/09\\\/prototype-design-pattern.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Prototype Design Pattern Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/ddd1b95af381c5042c09833e6a108e20\",\"name\":\"Rohit Joshi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/802a913bbb576309b246c8e839eaec9910390a9e7b8bf684a9706f8bfa3f6012?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/802a913bbb576309b246c8e839eaec9910390a9e7b8bf684a9706f8bfa3f6012?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/802a913bbb576309b246c8e839eaec9910390a9e7b8bf684a9706f8bfa3f6012?s=96&d=mm&r=g\",\"caption\":\"Rohit Joshi\"},\"description\":\"Rohit Joshi is a Senior Software Engineer from India. He is a Sun Certified Java Programmer and has worked on projects related to different domains. His expertise is in Core Java and J2EE technologies, but he also has good experience with front-end technologies like Javascript, JQuery, HTML5, and JQWidgets.\",\"sameAs\":[\"http:\\\/\\\/www.javacodegeeks.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/rohit-joshi\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Prototype Design Pattern Example - Java Code Geeks","description":"This article is part of our Academy Course titled Java Design Patterns. In this course you will delve into a vast number of Design Patterns and see how","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html","og_locale":"en_US","og_type":"article","og_title":"Prototype Design Pattern Example - Java Code Geeks","og_description":"This article is part of our Academy Course titled Java Design Patterns. In this course you will delve into a vast number of Design Patterns and see how","og_url":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-09-30T03:37:23+00:00","article_modified_time":"2023-12-07T09:20:36+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","type":"image\/jpeg"}],"author":"Rohit Joshi","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Rohit Joshi","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html"},"author":{"name":"Rohit Joshi","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/ddd1b95af381c5042c09833e6a108e20"},"headline":"Prototype Design Pattern Example","datePublished":"2015-09-30T03:37:23+00:00","dateModified":"2023-12-07T09:20:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html"},"wordCount":1115,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","keywords":["Design Patterns"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html","url":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html","name":"Prototype Design Pattern Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","datePublished":"2015-09-30T03:37:23+00:00","dateModified":"2023-12-07T09:20:36+00:00","description":"This article is part of our Academy Course titled Java Design Patterns. In this course you will delve into a vast number of Design Patterns and see how","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2015\/09\/prototype-design-pattern.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"Prototype Design Pattern Example"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/ddd1b95af381c5042c09833e6a108e20","name":"Rohit Joshi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/802a913bbb576309b246c8e839eaec9910390a9e7b8bf684a9706f8bfa3f6012?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/802a913bbb576309b246c8e839eaec9910390a9e7b8bf684a9706f8bfa3f6012?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/802a913bbb576309b246c8e839eaec9910390a9e7b8bf684a9706f8bfa3f6012?s=96&d=mm&r=g","caption":"Rohit Joshi"},"description":"Rohit Joshi is a Senior Software Engineer from India. He is a Sun Certified Java Programmer and has worked on projects related to different domains. His expertise is in Core Java and J2EE technologies, but he also has good experience with front-end technologies like Javascript, JQuery, HTML5, and JQWidgets.","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/rohit-joshi"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/44765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/967"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=44765"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/44765\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=44765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=44765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=44765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}