C# OOD Abstraction Principles
Posted on 2009-04-14
Hi there guys,
This will surely sound a bit elementary to the experienced programmer, but I feel I have missed an important concept of Inheritance (particularly abstraction).
The question is simple really:
I have a base class: "Request"
It contains several properties and methods which can be overridden.
Then I have a few derived classes, for example: "LookupRequest"
This classes inherits from Request, and overrides a couple properties/methods as stated above.
However, when creating an instance of LookupRequest using Polymorphism, I've ran into a problem. By typing something like:
Request request = new LookupRequest();
It works, however, I don't have access to any of the LookupRequest properties/methods. Just the base class (Request).
If I create an instance by implicitly typing:
var request = new LookupRequest();
Then I get access to the derived properties / methods as desired.
This seems like I'm missing an important concept to abstraction or polymorphism. Since you abstract classes are not meant and cannot by created instances, how does one properly invoke an inherited class?
Much thanks in advance!