From the course: Spring: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

The Prototype pattern

The Prototype pattern

From the course: Spring: Design Patterns

Start my 1-month free trial

The Prototype pattern

- [Instructor] Of all the patterns that we're going to talk about on this course, the prototype pattern is the one that I have used the least in raw Java. But it's one that I use quite often in Spring. And we're going to spend quite a bit of time focusing on the Spring side of this pattern. So let's talk about how it's used in Spring. Any bean that has its scope marked as prototype are treated as prototype beans. Now in Spring, the bean configuration itself is what is used as the prototype. In fact, in Java config, the actual bean method gets called every time that you need an instance of that object through the prototype scoping. New instances are created, not cloned as we will see in a traditional Java implementation when needed by the runtime and this is important. None of this work is actually done at startup, it is not done until the instance is actually needed and injected into the application context or the runtime itself. Now the traditional Java pattern is often done through…

Contents