You can use a base class (may be marked by MustInherit, but not a must) which define a default implementation for all the methods. Every concrete Visitor will inherit the base class and override only the methods it needs to.
Visitor Pattern with VB.Net
-
27-06-2023 - |
Question
Let's say I have a visitor interface like this:
''' <remarks>Visitor Pattern</remarks>
Public Interface IVisitor
Sub Visit(value As Type1)
Sub Visit(value As Type2)
Sub Visit(value As Type3)
Sub Visit(value As Type4)
Sub Visit(value As ...)
...
End Interface
Is there a way for my concrete visitors to avoid implementing Visit functions they don't need? I'd like to avoid doing stuff like this in my concrete visitors:
#Region "Methods not implemented (not needed)"
Public Sub Visit(value As Type4) Implements IVisitor.Visit
End Sub
...
I know that I can't use the Overridable
keyword in Interface
. So maybe I should just drop Interface
for Overridable Sub
in my base class?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow