https://github.com/quynhchi1009/prototype
Prototype is a creational design pattern that lets you copy existing objects without making your code dependent on their classes.
https://github.com/quynhchi1009/prototype
abstract-class design-patterns java
Last synced: about 2 months ago
JSON representation
Prototype is a creational design pattern that lets you copy existing objects without making your code dependent on their classes.
- Host: GitHub
- URL: https://github.com/quynhchi1009/prototype
- Owner: quynhchi1009
- Created: 2022-12-04T21:16:28.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-04T21:21:18.000Z (over 3 years ago)
- Last Synced: 2025-03-04T16:14:10.443Z (over 1 year ago)
- Topics: abstract-class, design-patterns, java
- Language: Java
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Prototype
Prototype is a creational design pattern that lets you copy existing objects without making your code dependent on their classes.
- declares a common interface for all objects that support cloning
Circle(Circle source) {
super(source);
this.radius = source.radius;
}
//The method clone() creates an object of the current class and carries over all of the field values of the old object into the new one.
public Shape clone() {
return new Circle(this);
}
- Prototype registry implementation with HashMap
- when your code shouldn’t depend on the concrete classes of objects that you need to copy
- when you want to reduce the number of subclasses that only differ in the way they initialize their respective objects
Prototype:
- isn’t based on inheritance, so it doesn’t have its drawbacks
- requires a complicated initialization of the cloned object
Factory Method:
- is based on inheritance
- doesn’t require an initialization step