Jump to content

Talk:Prototype pattern

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Mokru (talk | contribs) at 19:05, 26 February 2010 (Java example question). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

WikiProject iconJava Start‑class
WikiProject iconThis article is within the scope of WikiProject Java, a collaborative effort to improve the coverage of Java on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
???This article has not yet received a rating on the project's importance scale.
Note icon
This article has been automatically rated by a bot or other tool because one or more other projects use this class. Please ensure the assessment is correct before removing the |auto= parameter.
WikiProject iconComputer science Start‑class
WikiProject iconThis article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
???This article has not yet received a rating on the project's importance scale.
Things you can help WikiProject Computer science with:

What is GOF (references to an unidentified book)? Tom Peters 09:59, 18 January 2006 (UTC)[reply]

"Gang of Four": Design Patterns: Elements of Reusable Object-Oriented Software--Malcohol (talk) 09:23, 21 April 2008 (UTC)[reply]

If I create an object with certain properties, then use this to create another object (by passing it to a constructor) which will be initialised with those properties, this would seem to be a Prototype, but this is a little different from the GoF pattern - any thoughts? --- DannyAyers

Looks like a CopyConstructor to me. --- LairdNelson
You would lose the advantage of polymorphism that the GoF formulation of the Prototype pattern gives you. -- NatPryce
Exactly..Prototyping is all about a replica of myself .I don't know what i'm.ie polymorphism..But i can duplicate myself when some body else needs a duplicate of me and he don't care about my type (Hierarchy in the inheritance tree). --Praveen
By using Copy Constructor, this design pattern can be applied. But in C++ copy constructor is default property means you not need to declare it explicitly.But in other language may be copy constructor had to declare to provide such facility. In this case if some derived class in tree doesn't declare it then this pattern will fail for that hierarchy tree. That may be happen since OO language has the facility of reusability.So to keep pattern language independent I suggest declare the 'Clone' kind function as a pure virtual. That will force each drive class to provide Prototype facility. ---------Akash Gupta

Hey guys, moved the discussion here. If you have any other questions or things to discuss, place it here instead of in the article itself. : ) -Frecklefoot

The example link is dead ... Please use link http://wwwswt.informatik.uni-rostock.de/deutsch/Lehre/Uebung/Beispiele/PatternExamples/patexamples.htm

The example link is dead ... Please use link http://wwwswt.informatik.uni-rostock.de/deutsch/Lehre/Uebung/Beispiele/PatternExamples/patexamples.htm

62.39.121.226 13:31, 7 October 2005 (UTC)Rajiv[reply]


I wonder why the GoF authors say that Prototype is more complexe than Factory Method which relies on a hierarchy parallel to the Product hierarchy! I think there is a confusion between several problems that the pattern solves. First, Prototype solves the same problem as Factory Method, namely creating instances of classes without naming them. Second, it can be used to build objects faster or more easily by copying already built ones. There certainely are other uses for this pattern.

If the goal is to decouple clients from the classes to instantiate then I do not see why it would be more complex than Factory Method: on the contrary it is much simpler (no parallel hierarchy). The clone method is in fact a misnomer is this case: you do not need to clone a prototype p but simply want a new object of the same (dynamic) type as p. MikalZiane 13:05, 26 June 2006 (UTC)[reply]


"This pattern is used for example when the inherent cost of creating a new object in the standard way (e.g., using the 'new' keyword) is prohibitively expensive for a given application." - This sounds a bit misleading to me. The IMHO most common reason to use a clone() method instead of new is that you do not know the concrete type of the object, i.e. it is impossible to use new.

Java Code

Java example question

The introduction to the article says:

To implement the pattern, declare an abstract base class that specifies a pure virtual clone() method.

However, in the Java example the Cookie class is not declared abstract. Isn't this inconsistent with the introduction to the article?

210.23.150.138 (talk) 22:45, 4 November 2009 (UTC)[reply]

C++ Code

insane c++ code

why the heck did you people use this deprecated notation for the c++ code

its unnecessary and ugly in c++ code, since c++ handles strong typing way better than c did —The preceding unsigned comment was added by 212.201.67.61 (talk) 11:41, 17 April 2007 (UTC).[reply]

C++ code - Return type of clone() should be covariant

The c++ code example is flawed as the return type of clone should be covariant, i.e. CarRecord::clone() should return CarRecord * (not Record *), and BikeRecord::clone() should return BikeRecord *. Not using covariant return types creates unnecessary casts when calling clone for a derived object pointer. —Preceding unsigned comment added by 62.143.40.164 (talk) 19:41, 28 January 2008 (UTC)[reply]

C++ code - Another article seems like duplication

There is another article on c/c++ prototypes which should probably be merged with this article. Or at least edited. See http://en.wikipedia.org/wiki/Function_prototype --Mokru (talk) 18:59, 26 February 2010 (UTC) ==[reply]

C# issues

C# XPathNavigator

I think you have to go over the whole page again. It does not become clear when and why to use the clone method.

A good example is XPathNavigator in C#. Understand why they use the clone method here. If you understand this you understand the prototype pattern in a different way.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconXPathNavigatorOverDifferentStores.asp

Structure - Class Diagram

Sorry if I'm mistaken, but in the diagram, isn't the Client class implementing the Prototype superclass? (Due to the white triangle shape of the arrow).

Sorry also for the bad English.

Alpha (talk) 12:02, 16 February 2008 (UTC)[reply]

Wouldn't it make sense to give an example in JavaScript, which supports much of this natively? See http://steve-yegge.blogspot.com/2008/10/universal-design-pattern.html Jon (talk) 13:15, 13 February 2009 (UTC)[reply]