// Force all child classes to define how to be rendered.
public abstract class Shape
{
public abstract void Draw();
...
}
■
Note
Abstract methods can only be defined in abstract classes. If you attempt to do otherwise, you will be
issued a compiler error.
Methods marked with abstract are pure protocol. They simply define the name, return value
(if any), and argument set (if required). Here, the abstract Shape class informs the derived types “I
have a subroutine named Draw() that takes no arguments. If you derive from me, you figure out the
details.”
Given this, we are now obligated to override the Draw() method in the Circle class. If you do
not, Circle is also assumed to be a noncreatable abstract type that must be adorned with the
abstract keyword (which is obviously not very useful in this example). Here is the code update:
Do'stlaringiz bilan baham: |