Solved

prototype pattern

Posted on 2006-11-23
4
222 Views
Last Modified: 2010-03-31
can any one explain whats prototype pattern in laymans terms (without pointing me to a website :)

a simple example would be appreciated.

also is this pattern  widely used/ rarely used/ never used.

thanks
J
0
Comment
Question by:jaggernat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:gkishoreji
ID: 18005894
if u r familiar with java and the clone() method of an object, then
the object which u are going to clone is the prototype...
0
 
LVL 35

Expert Comment

by:girionis
ID: 18006784
The prototype patterns states that when the creation of an object is too expensive or complex, then you make copies of the original object instead of creating more objects.

For example, if you have a Person object that is created by querying the database several times and you want to create another Person object, instead of doing all the database stuff again, you just clone the first Person object and you get a copy. This is the prototype pattern.
0
 
LVL 10

Author Comment

by:jaggernat
ID: 18008109
is this pattern ever used in real life programming? Is it used in j2ee scenario?

thanks
0
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
ID: 18017716
Yes, it is and I have used it personally in the exampel I mentioned above. We had a Customer object that was very complicated and we needed to return it to the caller. This Customer object had loads of information inside it, it had an Address object, a BillingAccount object, an Order object, a Visit object etc. Each one of them was taken from the database and we had different queries, for instance one query for the customer itself, another for the address, another for the billing account etc. As you could see it was very expensive and time consuming. Later in the flow of the application we needed to create a customer instance, which would be the same customer with only a couple of fields different. Instead of querying the database again for the information we just used the prototype pattern and cloned the original Customer object. Then we made the changes in the secon d object. This saved us tremendous effort in system resources and execution time.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question