Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Prototype pattern
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Rules of thumb == Sometimes [[creational pattern]]s overlap—there are cases when either prototype or [[abstract factory pattern|abstract factory]] would be appropriate. At other times, they complement each other: abstract factory might store a set of prototypes from which to clone and return product objects.{{r|GoF|p=126}} Abstract factory, [[builder pattern|builder]], and prototype can use [[singleton pattern|singleton]] in their implementations.{{r|GoF|pp=81,134}} Abstract factory classes are often implemented with factory methods (creation through [[inheritance (object-oriented programming)|inheritance]]), but they can be implemented using prototype (creation through [[delegation (programming)|delegation]]).{{r|GoF|p=95}} Often, designs start out using Factory Method (less complicated, more customizable, subclasses proliferate) and evolve toward abstract factory, prototype, or builder (more flexible, more complex) as the designer discovers where more flexibility is needed.{{r|GoF|p=136}} Prototype does not require subclassing, but it does require an "initialize" operation. Factory method requires subclassing, but does not require initialization.{{r|GoF|p=116}} Designs that make heavy use of the [[composite pattern|composite]] and [[decorator pattern|decorator]] patterns often can benefit from Prototype as well.{{r|GoF|p=126}} A general guideline in programming suggests using the <code>clone()</code> method when creating a duplicate object during runtime to ensure it accurately reflects the original object. This process, known as object cloning, produces a new object with identical attributes to the one being cloned. Alternatively, ''instantiating'' a class using the <code>new</code> keyword generates an object with default attribute values. For instance, in the context of designing a system for managing bank account transactions, it may be necessary to duplicate the object containing account information to conduct transactions while preserving the original data. In such scenarios, employing the <code>clone()</code> method is preferable over using <code>new</code> to instantiate a new object.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Prototype pattern
(section)
Add topic