c# declare subclass as type superclass
c#, inheritance
Solution
It is often desirable to treat objects of concrete class polymorphically to avoid creating dependencies on specific types where you can avoid them. For example, if you are creating a `Circle` with the intention of drawing it, and `Draw()` is a method of a `Shape`, then it is better to declare `myCircle` as a shape, in case you decide to replace it with a square later on.
On the other hand, if your intention is to do something specific to `Circle`, say, to set its radius, then you need to declare `myCircle` as `Circle`, because `SetRadius()` may not be available on the `Shape`.
Problem
I can't seem to find a satisfactory answer to this inheritance question. Why do you declare a subtype like this sometimes: ``` Shape myCircle = new Circle(); ``` and this other times? ``` Circle myShape = new Circle(); ``` Where Circle is a child/sub-class of `Shape` ..... There doesn't seem to be consistency across the OO books I've been reading and an explanation I can get my head around. People have shown me examples of a Shapes class being instantiated for circles, squares, etc... But I don't understand when you use the 1st declaration and the second.