Different return values for Visitor pattern

akmon
Windoof-User
Windoof-User
Beiträge: 27
Registriert: 20. Okt 2009 18:58

Different return values for Visitor pattern

Beitrag von akmon »

Hi,

I wonder how we can provide a visitor interface with different return values?

Lets say we have following scenario: A given object structure and a visitor that pretty prints the object structure. That visitor interface has methods like "visit(someObject : SomeObject) : String" and the objects also have a "accept(visitor : Visitor) : String" method.

If I want to add a Visitor that evaluates this object structure I want to have visitor methods that return booleans.

Do I have to implement a second visitor interface with visit() methods that return boolean and must add a second accept() method to all objects?
Or is it ok to let the visit() and accept() methods return Object?

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Different return values for Visitor pattern

Beitrag von sproksch »

You could provide a visitor interface with "void" return value and a concrete visitor implementations that offers a getFormattedString() : String method, which can be used at the end, after traversing the expression tree (if I understand your question right). But, as stated in the other thread, you should base your solution of task 1 only on inheritance.

akmon
Windoof-User
Windoof-User
Beiträge: 27
Registriert: 20. Okt 2009 18:58

Re: Different return values for Visitor pattern

Beitrag von akmon »

The method in a concrete visitor is something that didn't came to my mind. Thanks :)

The task 1 was somehow very confusing for our team so we implemented it that way. At this stage of implementing raised this question.

Antworten

Zurück zu „Archiv“