I have a class Request.cs
It has an abstract method:
public abstract Response CreateResponse(XmlReader reader);
and there's also a method:
public Response SendRequest(string requestURI)
{
...
XmlReader reader = XmlReader.Create(responseStream);
return CreateResponse(reader);
}
The CreateResponse method
is implemented in a subclass that extends Request
. And that implementation returns response.
I don't understand how you can return a method like this that's an abstract method but the value returned is actually in the implementation of the method from the subclass. Is this an example of the Template Method pattern or just simple polymorphism, or is this "tricky or too savvy" code or even messy? I'm trying to figure out how this can even be done (is this basic OOP principal or design pattern) and is this a good practice or good use of OOP?