Web server logs - 394 Object-Oriented Programming: Polymorphism Chapter 10 interface appropriate

394 Object-Oriented Programming: Polymorphism Chapter 10 interface appropriate for all device drivers. Then, through inheritance from that abstract base class, derived classes are formed that all operate similarly. The capabilities (i.e., the public services) offered by the device drivers are provided as abstract methods in the abstract base class. The implementations of these abstract methods are provided in the derived classes that correspond to the specific types of device drivers. It is common in object-oriented programming to define an iterator class that can traverse all the objects in a container (such as an array). For example, a program can print a list of objects in a linked list by creating an iterator object, then using the iterator to obtain the next element of the list each time the iterator is called. Iterators often are used in polymorphic programming to traverse an array or a linked list of objects from various levels of a hierarchy. The references in such a list are all base-class references. (See Chapter 23, Data Structures, to learn more about linked lists.) A list of objects of base class TwoDimensionalShape could contain objects from classes Square, Circle, Triangle and so on. Using polymorphism to send a Draw message to each object in the list would draw each object correctly on the screen. 10.6 Case Study: Inheriting Interface and Implementation Our next example (Fig. 10.4 Fig. 10.8) reexamines the Point, Circle, Cylinderhierarchy that we explored in Chapter 9. In this example, the hierarchy begins with abstract base class Shape (Fig. 10.4). This hierarchy mechanically demonstrates the power of polymorphism. In the exercises, we explore a more substantial shape hierarchy. 1 // Fig. 10.4: Shape.cs 2 // Demonstrate a shape hierarchy using an abstract base class. 3 using System; 4 5 public abstract class Shape 6 { 7 // return Shape’s area 8 public virtual double Area() 9 { 10 return 0; 11 } 12 13 // return Shape’s volume 14 public virtual double Volume() 15 { 16 return 0; 17 } 18 19 // return Shape’s name 20 public abstract string Name 21 { 22 get; 23 } 24 } Fig. 10.4 Fig. 10.4Fig. 10FiFi.4g. 10.4g. 10.4Abstract Shapebase class.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Leave a Reply