Solved

prototype pattern

Posted on 2006-11-23
4
212 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
  • 2
4 Comments
 
LVL 5

Expert Comment

by:gkishoreji
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

743 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now