Chapter 6. Inheritance
The last chapter discussed association relationships, how one class can reference another class or set of classes using fields or properties. This chapter looks at another relationship between classes, that of inherita...
Derivation
It is reasonably common to want to extend a given type to add functionality, such as behavior and data. The purpose of inheritance is to do exactly that. Given a Person class, you create an Employee class that additionally contains Em...
Overriding the Base Class
All public and protected members of a base class are inherited in the derived class. However, sometimes the base class does not have the optimal implementation of a particular member. Consider the Name property on PdaItem...
Abstract Classes
Many of the inheritance examples so far have defined a class called PdaItem that defines the methods and properties common to Contact, Appointment, and so on, which are type objects that derive from PdaItem. PdaItem is not inten...
Everything Ultimately Derives from System.Object
Given any object, whether a custom class or one built into the system, the methods shown in Table 6.2 will be defined.
Table 6.2. Members of System.ObjectMethod NameDescriptionpublic virtual bool E...
Verifying the Underlying Type with the is Operator
Because C# allows casting down the inheritance chain, it is sometimes desirable to determine what the underlying type is before attempting a conversion. Also, checking the type may be necessary fo...
Conversion Using the as Operator
The advantage of the is operator is that it enables verification that a data item is of a particular type. The as operator goes one step further. It attempts a conversion to a particular data type just like a cast ...
Summary
This chapter discussed how to specialize a class by deriving from it and adding additional methods and properties. This included a discussion of the private and protected access modifiers that control the level of encapsulation.
This chap...
AJAX popular information C# language guides Windows books and cookbooks
.......
Mac Mini в Z-Store от 28490 руб - mac mini. Сделай компьютер удобным.
С 2009 года мы стали переводить структура сайта на различные языки. Сайт теперь будет содержать книги не только на английском языке, но также и на других европейских языках, в том числе и на Русском языке.