且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

访客模式:遍历客户或访客中的树元素

更新时间:2023-12-01 16:58:04

对于树结构而言,这似乎非常简单.节点中的accept方法如下所示:

It seems pretty straightforward for a tree structure. The accept method in a node could look like this:

void accept(Visitor visitor) {
    visitor.visitMyTypeOfNode(this);
    for each child {
        child.accept(visitor);
    }
}

显然,您需要考虑这对于您的应用程序的整体体系结构是否有意义.

Obviously you need to consider if this makes sense in the overall architecture of your application.