c# - Visitor Pattern "does not implement interface" error -
This is the first time that I try to implement the Visitor Pattern (using C #), I Sorry if I did something wrong! However, I have implemented this visitor pattern:
VisitableElement Public Interface {VisitorElement Visitor); } Public Interface Visitor Element {Void Travel (VisitableElement Cruising); } Public Square SomeClass: VisitableElement {... Public Zero Acceptance (VisitorElement Visitor) {...}} // Here are other classes implementing VisitableElement (for example not useful) Category Visitors: VisitorElement {... public void Visit (some class AOBZ) {...} // The implementation of the trip (one for each element of a category) ...} But when I compile this error I'm back to try:
Error 1 'Visitor' Interface Does not use 'namespaces'. Visitor Element. Visit (Namespace.Visual Element) ' ... but how do you do it? I implemented it through (some class Aobject) visits!
The funny thing is that if I try to add:
public zero travel (visitableelableable) {this.visit (viewable); } Then everything works fine, but it must be unnecessary to implement this way (and the first method should be enough!)
"post-text" itemprop = "text">
Interface VisitorElement requires that your class method implements void visit (VisitableElement visitable) < / Code>.
The visit method that you applied does not meet this requirement, because it only allows SomeClass type of argument
Each SomeClass is a VisitableElement , the interface requires that the method accepts any type that applies VisitableElement , Not just SomeClass .
If you want your visit method to accept only type arguments SomeClass , consider using the General < Code> VisitorElement & lt; T & gt; and a clear interface implementation:
Public Interface VisitableElement {Void acceptance (VisitorElement Visitor); } Public Class Some Class: Visible Element {Public Zero Accepted (Visitor Element Visit) {}} Public Interface VisitorElement {Zero Travel (VisibleLillable Visitable); } Public Interface Visitor Element & lt; T & gt; : Visitor Element Where T: Visitor Element {Zero Travel (T Visible); } Category Visitors: Visitor Element & lt; SomeClass & gt; {Public Zero Travel (Some Class Aobjects) {} Zero Visitor Element In this way, you can only call visits (some class AOzz) overload until you reach your Do not allow code> visitor to be placed on a non-normal VisitorElement in the non-normal visit method, you can visitable You can try entering SomeClass and call the normal version as a fallback (or whatever you want).
Because it is not completely clear to me that what you want to achieve, it is difficult to say what is the best thing in your case.
Comments
Post a Comment