javainterfaceimplementsvisitor-patterndouble-dispatch

Double dispatch using visitor pattern in Java


I have this architecture: architecture Visitor pattern

In XMLFormulaFormatter, I need the value of instances of Constant (instances which are created in my Main class).

I have this method in the Constant class:

public double asValue() { return value ; }

I have tried this code in XMLFormulaFormatter class:

@Override
     public String visit(Constant constant){ 
        latexConstant = constant.asValue() ;
        return "";
        }

But of course it does not give me the what I am looking at as I want to get the value of a specific instance of Constant...

I have also tried in the format() method of XMLFormulaFormatter:

@Override
    public String format(Formula format){ format.accept(this);
    if (format instanceof Constant){
        latexConstant= format.asValue();
        return "";
        }

But same result, as expected.

Any thoughts on how to get the value of a specific instance of Constant?

Thanks!


Solution

  • I think I have it, I need a getter in AbstractVariadicOperator