Prototype

xiaoxiao2021-03-05  23

I. Overview

The prototype mode belongs to the object creation mode. By giving a prototype object to specify the type of object to be created, then create more types of objects with the method of copying this object.

Second, the structure

1, simple form

Client: Requests for creating objects

Prototype: Abstract role gives the interface required for all specific prototypes

ConcretePrototype: Copyable object

2, registration form

PrototypeManager: Create and record specific objects

Third, shallow cloning and deep cloning

Shallow Clon: Only the clone of the refrence level, the object refers to the object referred to in the refrence is not cloned

Deep cloning: Recursing the objects referred to in Refrence to consider cloning depth and cycle cloning problems

Four, motive

Factory method for complex grade structure

Five, advantages and disadvantages

1. Allow the dynamically increase or decrease the product class, and there is no impact on the entire existing product structure.

2, provide a simplified creation structure

3, the ability to dynamically load new features

4, the product class does not need to have a certain level structure

I, each class must be equipped with a cloning method

转载请注明原文地址:https://www.9cbs.com/read-37100.html

New Post(0)