C++: doubts about visitor pattern

前端 未结 5 1591
天命终不由人
天命终不由人 2021-02-08 21:23

I know what Visitor Pattern is and how to use it; this question is not a duplicate of this one.


I\'ve got a library where I put most of the reusable code I write,

5条回答
  •  梦谈多话
    2021-02-08 21:41

    I understand absolutely what you said and I share the same concerns. The problem is that the Visitor Pattern is not very clearly defined and the original solution for it is misleading, IMHO. This is why there are so many variations of this pattern.

    In particular, I believe that the correct implementation should support legacy code, I mean: a binary you've lost the source code at all, isn't it? This is what the definition says: that you should never had to change the original data structures.

    I don't like implementations with visitA, visitB, visitWhatever, acceptA, acceptB, acceptWhatever. This is absolutely wrong, IMHO.

    If you have a chance, please have a look at an article I've written about this.

    It's Java, but you can port to C++ easily if you find it useful for your purposes.

    I hope it helps

    Cheers

提交回复
热议问题