Chapter 9 Object-Oriented Programming: Inheritance 377 Line 17

Chapter 9 Object-Oriented Programming: Inheritance 377 Line 17 instantiates another object of class Circle5, then assigns it to reference circle2. Again, this begins the chain of constructor calls in which the Circle5 constructor, the Point4 constructor and the Object constructor are called. In the output, notice that the body of the Point4constructor executes before the body of the Circle5 constructor. This demonstrates that objects are constructed inside out (i.e., the base-class constructor is called first). Lines 22 23 set references circle1 and circle2to null. This removes the only references to these Circle5 objects in the program. Thus, the garbage collector can release the memory that these objects occupy. Remember that we cannot guarantee when the garbage collector will execute, nor can we guarantee that it will collect all available objects when it does execute. To demonstrate the destructor invocations for the two Circle5 objects, line 26 invokes class GC s method Collect to request the garbage collector to run. Notice that each Circle5 object s destructor outputs information before calling class Point4 s destructor. Objects are destroyed outside in (i.e., the derived- class destructor completes its tasks before invoking the base-class destructor). 9.7 Software Engineering with Inheritance In this section, we discuss the use of inheritance to customize existing software. When we use inheritance to create a new class from an existing one, the new class inherits the member variables, properties and methods of the existing class. We can customize the new class to meet our needs by including additional member variables, properties and methods, and by overriding base-class members. Sometimes, it is difficult for students to appreciate the scope of problems faced by designers who work on large-scale software projects in industry. People experienced with such projects say that effective software reuse improves the software-development process. Object-oriented programming facilitates software reuse, thus shortening development times. C# encourages software reuse by providing the .NET Framework Class Library (FCL), which delivers the maximum benefits of software reuse through inheritance. As interest in C# grows, interest in the FCL class libraries also increases. There is a worldwide commitment to the continued evolution of the FCL class libraries for a wide variety of applications. The FCL will grow as the .NET world grows explosively. Software Engineering Observation 9.11 At the design stage in an object-oriented system, the designer often determines that certain classes are closely related. The designer should factor out common attributes and behaviors and place these in a base class. Then, use inheritance to form derived classes, endowing them with capabilities beyond those inherited from the base class. Software Engineering Observation 9.12 The creation of a derived class does not affect its base class s source code. Inheritance preserves the integrity of a base class. Software Engineering Observation 9.13 Just as designers of non-object-oriented systems should avoid proliferation of functions, designers of object-oriented systems should avoid proliferation of classes. Proliferation of classes creates management problems and can hinder software reusability, because it becomes difficult for a client to locate the most appropriate class of a huge class library. The
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Leave a Reply