class, it would inherit from the Animal class, and all public properties and
methods of Animal would be available to instances of the Dog class.
Similarly, we could create a new class based on the Dog class. In programming
circles, this is called deriving a subclass from Dog. For instance, we might create
a class called AustralianShepherd, and one for my other dog, Amigo, called
Chihuahua, both of which would inherit the properties and methods of the Dog
base class, and define new classes specific to each breed.
Don’t worry too much if this is still a little unclear. The best way to appreciate
inheritance is to see it used in a real program. The most obvious use of inheritance
in ASP.NET is in the technique called code-behind, and we’ll build plenty of ex-
amples using inheritance and code-behind in Chapter 4.
Objects In .NET
If this is the first book in which you’ve read about object oriented programming,
you’ve probably started to dream about objects! Don’t worry, the effect of first
exposure to objects doesn’t usually last for more than a week. Even though this
is yet another discussion about objects, I promise it won’t be boring. Moreover,
in the course of this section, we’ll cover some important concepts that every ser-
ious .NET programmer must know.
So far, we’ve explored various concepts that apply in one form or the other to
almost any truly object oriented language. Every language has its peculiarities,
but the general concepts are the same in all of these languages.
You may already have heard the common mantra of object oriented programmers:
“everything is an object.” This has two meanings. First of all, in C#, every program
consists of a class. In all stages of application development, from design to imple-
mentation, decisions must be made in regard to the way we design and relate
objects and classes to each other. Yes, objects are everywhere.
.NET extends this to yet another level, giving the phrase “everything is an object”
extra meaning. In the world of .NET, every class ultimately derives from a base
class named Object, so “everything is an object” becomes “everything is an Ob-
ject.”
If you look at the documentation for the ASP.NET Page class, you can see the
list of classes from which this class inherits, as shown in Figure 3.7.
85
Objects In .NET