"Design Mode Design Pattern" reading notes twenty-one

xiaoxiao2021-03-06  18

"Design Mode Design Pattern" reading notes twenty-one

Visitor mode

structure

purpose

When an object (Node) is relatively fixed, all Node in this structure is accessed by creating a Visitor object; instead of creating a member function in each Node; this Node structure does not need to change, You can increase the Visitor object at will increase the different access action on the Node structure.

discuss

1. If Node frequently modifies (increase / decrease, etc.), Visitor mode is not suitable. Because Node changes, it is involved in modifying all Visitor interfaces.

2, Node needs to provide a certain function to visitor access, which will slightly damage the encapsulation.

3, there can be three ways to make a convenience of the Node structure: Node itself, Visitor, an Iterator

Reference

"Design Pattern" Gang-Of-4 1997

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

New Post(0)