Search code examples
javadesign-patternscloneableprototype-pattern

Is Prototype an anti pattern?


When Joshua Bloch mentions that Cloneable interface is broken in Java, why is the Prototype pattern, which uses clone() method to facilitate object creation, not considered an anti-pattern in Java development?

"It's a shame that Cloneable is broken, but it happens." - Joshua Bloch


Solution

  • No, Prototype is not an antipattern.

    Prototype Design Pattern is language-agnostic. It applies to many other object-oriented programming languages, and it has multiple possible implementations.

    Although the implementation that was designed into the Java class library is, indeed, broken, it does not mean that the pattern is broken, too. All it means is that if you would like to use this pattern in your design, you should stay away from the built-in support for it, and make your own instead.