I have an interface : ISearch<T>, and I have a class that implements this interface:FileSearch : ISearch<FileSearchResult>
I have a class FileSearchArgs : SearchArgsthat has a method to return a search object:
public override ISearch<SearchResult> getSearchObject ()
{
return ((ISearch<SearchResult>)new FileSearch());
}
This is canceled from:
public virtual ISearch<SearchResult> getSearchObject () { return null; }
The code will only be built if I provided a cast to (ISearch), but it throws an exception at runtime with a transfer error. In addition, the previous iteration did not apply generalization to the interface, and therefore the method signature getSearchObject()was as follows:
public override ISearch getSearchObject() { return new FileSearch();}
I know that one of the solutions could be to return the base class "Search" instead of implementing the interface, but I would prefer not to do this and understand why I can not follow the pattern that I previously had.
, . , , , - , , !
.