这种模式叫什么(有助于避免类型转换)?

时间:2021-04-04 20:38:29

Found myself trying to find a link to an official definition of this design pattern which I believe I saw in Go4 but can't seem to find it anywhere.

发现自己试图找到这个设计模式的官方定义的链接,我相信我在Go4中看到过,但似乎无法在任何地方找到它。

class Processor{
    ProcessParameter(AbstractParameter x){
        x.Process(this);
    }

    ProcessParameter(ParameterA x){
        ... A-specific logic...
    }

    ProcessParameter(ParameterB x){
        ... B-specific logic...
    }
}

abstract class AbstractParameter{
    abstract void Process(Processor p);
}

class ParameterA : AbstractParameter{
    override void Process(Processor p){
        p.ProcessParameter(this);
    }
}

class ParameterB : AbstractParameter{
    override void Process(Processor p){
        p.ProcessParameter(this);
    }
}

1 个解决方案

#1


It is the Visitor Pattern. The technique is called "double dispatch".

这是访客模式。该技术称为“双重调度”。

#1


It is the Visitor Pattern. The technique is called "double dispatch".

这是访客模式。该技术称为“双重调度”。