1

I don't think spring does use clone in making a proto, it will be cheating if they use reflection API and create a copy object and call it a clone/proto, Springs proto never satisfies any condition of prototype pattern.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
  • Possible duplicate of [Spring prototype following prototype design pattern](http://stackoverflow.com/questions/26609980/spring-prototype-following-prototype-design-pattern) – jaco0646 Jul 25 '16 at 19:58

1 Answers1

1

Yes, you are right. The @Scope("prototype") annotation in Spring doesn't implement the prototype design pattern by the GoF. While the prototype design pattern creates new objects by cloning a given prototype (see here), Spring's @Scope("prototype") will not do that. It will create a new object every time by Spring's default object creation mechanism (which is reflection I guess). If you look at Spring's documentation, it evens says that @Scope("prototype") is a replacement for Java's new operator:

In some respects, the Spring container’s role in regard to a prototype-scoped bean is a replacement for the Java new operator.

(See here)

izilotti
  • 4,757
  • 1
  • 48
  • 55
Thomas Uhrig
  • 30,811
  • 12
  • 60
  • 80
  • Thanks Mr. Thomas, My advice to spring community is to change the word prototype to multiton, if they do so then there is no issue, and more over prototype (cloning) is a very good concept, they should provide implementation for this too – Mohammad Shoiab Sep 28 '15 at 10:23