366 Object-Oriented Programming: Inheritance Chapter 9 Point3 s base (Web hosting india)
366 Object-Oriented Programming: Inheritance Chapter 9 Point3 s base class) is declared virtual. Method ToStringof class Circle4displays the privateinstance variables xand yof class Point3by calling the base class s ToStringmethod (in this case, Point3 s ToStringmethod). The call is made in line 62 via the expression base.ToString() and causes the values of x and y to become part of the Circle4 s string representation. Using this approach is a good software engineering practice: Recall that Software Engineering Observation 8.11 stated that, if an object s method performs the actions needed by another object, call that method rather than duplicating its code body. Duplicate code creates code-maintenance problems. By having Circle4 s ToString method use the formatting provided by Point3 s ToString method, we avoid duplicating code. Also, Point3 s ToStringmethod performs part of the task of Circle4 s ToString method, so we call Point3 s ToString method from class Circle4with the expression base.ToString(). Common Programming Error 9.3 When a base-class method is overridden in a derived class, the derived-class version often calls the base-class version to do additional work. Failure to use the base reference when referencing the base class s method causes infinite recursion, because the derived-class method would then call itself. Common Programming Error 9.4 The use of chained base references to refer to a member (a method, property or variable) several levels up the hierarchy (as in base.base.mX) is a syntax error. Software Engineering Observation 9.8 A redefinition in a derived class of a base-class method that uses a different signature than that of the base-class method is method overloading rather than method overriding. Software Engineering Observation 9.9 Although method ToString certainly could be overridden to perform arbitrary actions, the general understanding in the C# .NET community is that method ToString should be overridden to obtain an object s string representation. Class CircleTest4 (Fig. 9.14) performs identical manipulations on class Circle4 as did classes CircleTest (Fig. 9.7) and CircleTest3 (Fig. 9.11). Note that the outputs of all three modules are identical. Therefore, although each circle class appears to behave identically, class Circle4 is the most properly engineered. Using inheritance, we have efficiently and effectively constructed a well-engineered class. 1 // Fig. 9.14: CircleTest4.cs 2 // Testing class Circle4. 3 4 using System; 5 using System.Windows.Forms; 6 7 // CircleTest4 class definition 8 class CircleTest4 9 { Fig. 9.14 Fig. 9.14Fig. 9.FiFi14g. 9.14g. 9.14CircleTest4demonstrates class Circle4functionality. (Part 1 of 2.)
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.