Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

prototype pattern

Posted on 2006-11-23
4
Medium Priority
?
233 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses

609 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