Overview
In software systems, product classes sometimes change dynamically and have a certain hierarchical structure. In this case, if the factory model is used, the factory method classes parallel to the product class hierarchy will also change with this change, which is obviously not suitable. So how can we encapsulate this dynamic change? So that the client programs dependent on these variable objects do not change with the product class?
Intention
In software systems, the creation of "some objects with complex structures" is often faced. due to changes in requirements, these objects are often faced with drastic changes, however, they have stable and consistent interfaces. How to deal with this change? How can we isolate "these variable objects" from "customer programs (programs using these objects)" so that "customer programs dependent on these variable objects" will not change as demand changes?
<Design Pattern> example
Biological examples
In Prototype mode, a Prototype instance is used to specify the type of the object to be created. The prototype of a new product is usually created before all products. Such prototype is passive and does not participate in copying itself. The split of a cell produces two identical cells. This is an example of assuming an active role to copy its own prototype. This demonstrates the prototype. One Cell Division produces two cells of the same genotype. In other words, the cell clones itself.
Dependency inversion
-Abstract A directly depends on implementation details B
Abstraction should not depend on implementation details, but on abstraction.
-Abstract A depends on abstract B.
Details B depends on abstract B
Example:
A wolf is very team-oriented. Every appearance is a group of wolves. This time, we give an example of the appearance of four wolves. we only need to provide a wolf instance, and all the others will copy it and change the attribute. this mode is exactly our prototype.
Structure:
The following code is created:
Create Location. cs First:
Html # viewSource "commandName =" viewSource "highlighterId =" highlighter_504075 "> view sourceprint?