15.1. What is Inheritance?

Up until now, inheritance has been a concept sitting in the background, making your life easier every time you designed a user interface for your programs. Indeed, you have probably glossed over the fact that the program line

public class frmMain : Form

enabled you to inherit all of the basic functionality of a Windows form without having to write that code yourself. In fact, the colon in the preceding statement could be verbalized as "inherits from." The concept of inheritance is built upon the notion that many objects share similar properties. In the preceding statement, you are stating that you wish to create a new class named frmMain that inherits all of the functionality of a basic Windows form. Being able to inherit this functionality means that you don't have to write, test, debug, and maintain that inherited code yourself. Therefore, the driving force behind inheritance is to simplify writing code. Inheritance makes it possible for your code to extend one class to suit your specific needs. Simply stated, inheritance is the ability to take one class and extend that class to suit a similar, albeit different, purpose. An example will help explain inheritance.

15.1.1. An Inheritance Example

Some time ago I was contracted to write a program for a real estate investor. The type of real estate the investor purchased could be classified as apartments, commercial properties (such as small strip malls), and residential homes. I sat down with her and asked ...

Get Beginning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.