1

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:

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).

3 Answers 3

2

According to Josh Bloch and Doug Lea, Cloneable is broken. In that case, you can use a copy constructor.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for this link - I've also added a reference to mutable/immutable objects in the question.
Object.clone is broken. But cloning manually is still fine.
This distinction really is what I wanted to suggest. ie Cloneable as a marker interface, and void clone throws CloneNotSupportedException
0

Steve Yegge describes the Eclipse implementation of the ASTNode

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.