Web hosting companies - Chapter 9 Object-Oriented Programming: Inheritance 379 It

Chapter 9 Object-Oriented Programming: Inheritance 379 It is possible to treat base-class objects and derived-class objects similarly; the commonality shared between the object types is expressed in the member variables, properties and methods of the base class. A base class s public members are accessible anywhere that the program has a reference to an object of that base class or to an object of one of that base class s derived classes. A base class s private members are accessible only within the definition of that base class. A base class s protected members have an intermediate level of protection between public and private access. A base class s protected members can be accessed only in that base class or in any classes derived from that base class. A base class s internal members can be accessed only by objects in the same assembly. Unfortunately, the inclusion of protectedinstance variables often yields two major problems. First, the derived-class object does not have to use a property to set the value of the base-class s protected data. Second, derived class methods are more likely to be written to depend on base- class implementation. C# rigidly enforces restriction on accessing private data members, so that even derived classes (i.e,. which are closely related to their base class) cannot access base-class private data. When a derived-class method overrides a base-class method, the base-class method can be accessed from the derived class by preceding the base-class method name with the base reference, followed by the dot operator (.). A derived class can redefine a base-class method using the same signature; this is called overriding that base-class method. A base-class method must be declared virtual if that method is to be overridden in a derived class. When a method is overridden in a derived class and that method is called on a derived-class object, the derived-class version (not the base-class version) is called. When an object of a derived class is instantiated, the base class s constructor is called immediately (either explicitly or implicitly) to do any necessary initialization of the base-class instance variables in the derived-class object (before the derived classes instance variable are initialized). Declaring member variables private, while providing non-private properties to manipulate and perform validation checking on this data, enforces good software engineering. If an object s method/property performs the actions needed by another object, call that method/property rather than duplicating its code body. Duplicated code creates code-maintenance problems. Base-class constructors and destructors are not inherited by derived classes. TERMINOLOGY abstraction data abstraction base class default constructor base-class constructor derived class base-class default constructor derived-class constructor base-class finalizer derived-class reference base-class object direct base class base-class reference dot (.) operator behavior garbage collector class library has-a relationship colon (:) symbol hierarchy diagram composition indirect base class constructor information hiding
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Leave a Reply