From the course: Java Design Patterns: Creational
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Understand the Prototype pattern - Java Tutorial
From the course: Java Design Patterns: Creational
Understand the Prototype pattern
- [Instructor] The prototype pattern essentially involves making a copy of one original object. It is useful when you want to create a new object, but a similar one already exists. In particular, it should be used when you do not want a system to know details of how objects are created. Say for example, there is an application that simulates a field of rabbits, and the while the application is running, the rabbits breed. Instead of creating a new rabbit object each time, it would be easier and more efficient to clone a single prototype rabbit. This technique is particular useful if creating a new rabbit object is a memory-intensive process. It can make the application faster, as well as make the code shorter and cleaner. If the prototype pattern is used and an original rabbit is copied. The copied rabbits can then be modified . For example, you could clone the original rabbit 10 times, and then give all of the rabbits their own name. This pattern should be used when the application…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.