Introduction to ASP.NET - Object Orientation in the .NET Platform
(Page 6 of 10 )
The .NET Framework was built to be object oriented from the ground up. What does this mean? For those of you who are unfamiliar with object-oriented programming, here’s a quick review.
We’ve already discussed classes. Classes are the blueprints or templates from which objects are created. Objects, the heart of object-oriented programming, are usable instances of a class. Objects expose properties, which contain data related to or about the object, and/or methods, which allow actions to be performed on the object.
In object-oriented programming, objects need to support three important qualities: encapsulation, inheritance, and polymorphism.
Encapsulation refers to the ability of an object to hide its internal data from outside view and allow access to only that data through publicly available methods. This helps prevent clients from accidentally or purposefully leaving object data in a corrupt state and makes it easier for the developer of the class on which the object is based to change the internal implementation of these data members without breaking its clients.
Inheritance refers to the ability to derive one class from another. This allows developers to create a new class based on an existing class. The new class inherits all methods and properties of the existing class. The developer can then add new methods or properties or override existing methods. Inheritance allows you to develop specialized versions of objects that are customized to meet your precise needs. We’ll discuss this type of scenario more in Chapter 6.
The .NET Framework offers only single inheritance—that is, a class may only derive from a single base class. This is different from languages such as C++, which allow classes to be derived from multiple base classes.
Polymorphism refers to the ability of multiple classes derived from the same base class to expose methods with the same name—all of which clients can call in exactly the same way, regardless of the underlying implementation. Thus, a Car class could expose a Start method and a derived class SportsCar could override that Start method to provide a different implementation. From the client’s perspective, however, both methods are used the same way.
This is a very high-level overview of object-oriented programming. While we’ll discuss object-oriented techniques in more depth throughout the book, if you are unfamiliar with the topic you may want to pick up a book that specifically addresses object-oriented programming.
Why Is It Important? Rapid Development and Reuse! What’s important about the object-oriented nature of the .NET platform is that it allows much faster development than did previous generations of Windows development technologies and offers much greater opportunities for reuse.
Because the functionality of the .NET Framework is exposed as a set of object-oriented classes rather than a set of obscure and finicky API calls, many operations that were difficult or downright impossible in classic ASP are simple in ASP.NET. For example, about ten lines of code can perform a DNS lookup on a domain name using the classes in the System.Net and System.Net.Sockets namespaces. This task wasn’t even possible in classic ASP, without the use of external components.
What’s more, because many classes in the .NET framework can be used as base classes, it is easy to reuse them in your own applications by deriving from a class to provide common functionality and then extending the derived class to add functionality specific to your application. In fact, much of the .NET Framework is built this way. For example, all classes that make up the ASP.NET Server Controls are ultimately derived from the Control class of the System.Web.UI namespace, which provides properties and methods common to all server controls.
 | If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!
Visit the O'Reilly Network http://www.oreillynet.com for more online content. |
Next: OO Is at the Heart of Every ASP.NET Page >>
More ASP.NET Articles
More By O'Reilly Media