Solved

prototype pattern

Posted on 2006-11-23
4
220 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

738 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