Java implementations of the Prototype Pattern
What implementations of the Prototype Pattern exist on the Java platform?
A prototype pattern is a creational design pattern used in software development when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects.
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior reuse (known as inheritance in class-based languages) is performed via a process of cloning existing objects that serve as prototypes.
The implementation should be aware that some Java objects are mutable, and some are immutable (see Mutable vs Immutable objects).
Asked by: Melissa855 | Posted: 28-01-2022
Answer 1
According to Josh Bloch and Doug Lea, Cloneable is broken. In that case, you can use a copy constructor.
Answered by: Ada995 | Posted: 01-03-2022Answer 2
Steve Yegge describes the Eclipse implementation of the ASTNode
Answered by: Daisy543 | Posted: 01-03-2022Answer 3
Java defines the Cloneable interface, described here at JGuru
Java provides a simple interface named Cloneable that provides an implementation of the Prototype pattern. If you have an object that is Cloneable, you can call its clone() method to create a new instance of the object with the same values.
Warning: see Cloneable is broken
Answered by: Aston412 | Posted: 01-03-2022Similar questions
java - Using scope prototype on abstract component with anonymous implementations
I have the following scenario:
@Component
@Scope("prototype")
public abstract class AbstractA {
protected abstract String getData();
}
Now I will require to create instances of this class in a dynamic manner (using anonymous inner classes). Such as:
@Component
public class B {
public void some_method() {
//Obviously this is wrong, I want to be able to do thi...
java - abstract methods in skeletal implementations of interfaces
I was re-reading Effective Java (2nd edition) item 18, prefer interfaces to abstract classes. In that item Josh Bloch provides an example of a skeletal implementation of the Map.Entry<K,V> interface:
// Skeletal Implementation
public abstract class AbstractMapEntry<K,V>
implem...
java - Where should you use BlockingQueue Implementations instead of Simple Queue Implementations?
I think I shall reframe my question from
Where should you use BlockingQueue Implementations instead of Simple Queue Implementations ?
to
What are the advantages/disadvantages of BlockingQueue over Queue implementations taking into consideration aspects like speed,concurrency or other properties which vary e.g. time to access last element.
I have used both kind of Queues. I...
java - Is it safe to assume that Spring MessageSource implementations are thread-safe?
Is it safe to assume that all implementations of org.springframework.context.MessageSource interface are thread-safe after initialization?
I would expect that it's safe, but now I'm looking through Spring source code, and there's org.springframework.context.support.ReloadableResourceBundleMessageSource which reloads properties from time to time, and documentation doesn't say anything about being thread-safe...
...
Factory methods for implementations of Java interfaces wrapped with Scala implicits?
I'm using Scala implicits to define a rich wrapper for a Java interface:
class RichThing { def richStuff: Unit = {} }
In the companion object I define the implicit conversion and an apply factory method:
object RichThing {
implicit def rich( thing: JavaThing ) = new RichThing()
def apply() = new RichThing()
}
With this, I can instant...
java - JPA Implementations - Which one is the best to use?
java - Compare JSF implementations
java - Differences between JVM implementations
Where do JVM Implementations differ (except licensing)?
Does every JVM implement Type Erasure for the Generic handling?
Where are the differences between:
JRockit
IBM JVM
SUN JVM
Open JDK
Blackdown
Kaffe
.....
Deals one of them with Tail-Call-Optimization?
java - Any open source implementations of WS-DM working with JMX?
Closed. This question does not meet Stack Overflow guid...
Free C/C++ and Java implementations of PPP?
Are there free C/C++ and Java implementations of the point-to-point protocol (PPP) for use over a serial line? The C/C++ implementation will go into embedded hardware so portability is a concern. I'm not looking for a full TCP/IP stack, just something to provide a connection-oriented base to build on top of.
performance - Optimized implementations of java.util.Map and java.util.Set?
I am writing an application where memory, and to a lesser extent speed, are vital. I have found from profiling that I spend a great deal of time in Map and Set operations. While I look at ways to call these methods less, I am wondering whether anyone out there has written, or come across, implementations that significantly improve on access time or memory overhead? or at least, that can improve these things given some assu...
Still can't find your answer? Check out these amazing Java communities for help...
Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)