Prototype Pattern)

Source: Internet
Author: User

Prototype (prototype ):Use a prototype instance to specify the type of the object to be created, and copy the prototype to create a new object.

The prototype mode is used when a system is created, constructed, and expressed independently of its products;

When the class to be instantiated is scheduled at the runtime, for example, through dynamic loading, or to avoid creating a factory class level parallel to the product class level;

When an instance of a class can only have one of several combinations of different States. Creating prototype and cloning them may be more convenient than manually instantiating this type with the appropriate state each time.

Personal Opinion:

To put it bluntly, an icloneable interface is implemented, which contains a clone method that allows you to build a superficial copy of the object through the clone method.

The so-calledA superficial copy indicates that if a field is of the value type, the field is copied one by one. If the field is of the reference type, the reference is copied, but the referenced object is not copied.. Therefore, if a field of the reference type exists in the class, only one reference of the method can be copied when memberwiseclone () is called to implement the clone interface method.

If you perform deep replication, a new object is also specified for the reference type. The framework does not provide a method for deep replication. You need to implement it yourself. Similar to dataset's clone () and copy () methods, one is superficial replication, and the other is deep replication.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.