Free web space - Chapter 10 Object-Oriented Programming: Polymorphism 393 syntax error.
Chapter 10 Object-Oriented Programming: Polymorphism 393 syntax error. Every concrete derived class must override all base-class abstract methods and properties (using keyword override) and provide concrete implementations of those methods or properties. Any class with an abstract method in it must be declared abstract. The difference between an abstract method and a virtual method is that a virtual method has an implementation and provides the derived class with the option of overriding the method; by contrast, an abstract method does not provide an implementation and forces the derived class to override the method (for that derived class to be concrete). Common Programming Error 10.5 Defining an abstract method in a class that has not been declared as abstract results is a syntax error. Common Programming Error 10.6 Attempting to instantiate an object of an abstract class results in a compilation error. Common Programming Error 10.7 Failure to override an abstract method in a derived class is a syntax error, unless the derived class also is an abstract class. Software Engineering Observation 10.7 An abstract class can have instance data and non-abstract methods (including constructors), which are subject to the normal rules of inheritance by derived classes. Although we cannot instantiate objects of abstract base classes, we can use abstract base classes to declare references; these references can refer to instances of any concrete classes derived from the abstract class. Programs can use such references to manipulate instances of the derived classes polymorphically. Let us consider another application of polymorphism. A screen manager needs to display a variety of objects, including new types of objects that the programmer will add to the system after writing the screen manager. The system might need to display various shapes, such as Circle, Triangle or Rectangle, which are derived from abstract class Shape. The screen manager uses base-class references of type Shape to manage the objects that are displayed. To draw any object (regardless of the level at which that object s class appears in the inheritance hierarchy), the screen manager uses a base-class reference to the object to invoke the object s Draw method. Method Draw is an abstract method in base class Shape; therefore, each derived class must implement method Draw. Each Shape object in the inheritance hierarchy knows how to draw itself. The screen manager does not have to worry about the type of each object or whether the screen manager has ever encountered objects of that type. Polymorphism is particularly effective for implementing layered software systems. In operating systems, for example, each type of physical device could operate quite differently from the others. Even so, commands to read or write data from and to devices may have a certain uniformity. The write message sent to a device-driver object needs to be interpreted specifically in the context of that device driver and how that device driver manipulates devices of a specific type. However, the write call itself really is no different from the write to any other device in the system place some number of bytes from memory onto that device. An object-oriented operating system might use an abstract base class to provide an
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.