. NET design Pattern example prototype (Prototype pattern)

Source: Internet
Author: User
Tags shallow copy

Introduction of prototype Model (Brief Introduction)

Prototype mode (Prototype pattern): Specifies the type of object to create with a prototype instance, and creates a new object by copying the prototypes.

Specify the kind of objects to create using a prototypical instance, and create new objects by copying this prototype.

Shallow copy differs from deep copy:

Shallow copy, all the variables copied have the same value as the original object, and all references to other objects still point to the original object.

Deep copy, referring to the object's variable to the copied new object, not the original referenced object.

NET namespace system provides a iconeable interface with only one method clone (), which can be implemented as a prototype (Prototype pattern) with the implementation of this interface.

Ii. issues addressed (What to Solve)

You can consider using prototype mode when an object generation is not through new but by copying old objects.

Prototype Model Analysis 1, prototype pattern structure

Prototype class: Prototype Class Clone () method: Clones its own interface.

Concreteprototypea, Concreteprototypea class: The concrete realization of the prototype class. Clones an operation of its own.

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.