Creating and Implementing Class Hierarchies
What You Will Learn in This Chapter
- Deriving one class from another
- Calling base class constructors
- Defining and implementing interfaces
- Using important interfaces such as IComparable, IEquatable, and IEnumerable
- Managing resources by implementing IDisposable and providing destructors
WROX.COM CODE DOWNLOADS FOR THIS CHAPTER
You can find the code downloads for this chapter at www.wrox.com/remtitle.cgi?isbn=1118612094 on the Download Code tab. The code is in the chapter05 download and individually named according to the names throughout the chapter.
Chapter 4, “Using Types,” explains how you can convert data between various data types. Some of the conversions are between primitive types such as converting a float value into an int or converting a DateTime value into a string.
Some of the most interesting type conversions, however, are between one object type and another. For example, if the Employee class inherits from the Person class, you can convert a reference to an Employee into a reference to a Person because an Employee is a kind of Person.
This chapter explains how you can build hierarchies of classes such as the Person-Employee hierarchy. It also explains how to create and use interfaces, which provide another form of inheritance. Finally, this chapter explains how to manage an object’s resources when the object is destroyed.
Table 5-1 introduces you to the exam objectives covered in this chapter.