Solved

prototype pattern

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 74
servlet example issue 6 40
servlet filter example 37 63
spring jars download 1 29
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

831 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