Using Object-Orientation in ASP.NET : OverviewBy Ian Stallings
With all the excitement surrounding ASP.NET and what it can do for you, it's easy to miss the major change that slipped by - the change to a totally Object-Oriented paradigm. (To learn more about ASP.NET, be sure to read our ASP.NET Article Index!) Visual Basic 7 will fully embrace OO as will C#, Microsoft's newest language. Make no mistake. This is a direct shot at Sun's Java development environment. Java/JSP has always supported OO, making it more appealing to developers accustomed to working within the OO paradigm. This will all change with ASP.NET and it's built in support for VB7, and C#.
What is Object-Orientation?
Object-Orientation is a paradigm for creating software systems using objects. Objects are tangible and conceptual things we find in the real world. Using OO, the code is broken into modular, reusable chunks called classes. Classes are the "blueprint" for creating instances of objects. These classes can be used throughout an application again and again. The entire concept of OO is beyond the scope of this article, so I would recommend reading up on OO at some of the links listed below for more information.
What Are The Benefits Of OO?
OO emphasizes creating reusable, robust software in a way that is easy to understand. By relating programming to the real world, it becomes much easier to use. Some of the characteristics of OO are:
- Reusable - faster, modular development
- Robust - increased quality
- Simple - easy maintenance
- Flexible - easy to modify
There are a lot of concepts involved with OO. But let's just cover the basics for now and maybe this will help you get a better understanding of OO:
- Classes - A generic blueprint used to create similar objects. We can have a
Humanclass for instance. All of these humans would breather air, have a head, etc. Specific instances of these objects may be different, having different heads, but they would all share the same characteristics. (To learn more about classes and using classes in old-school ASP with VBScript, be sure to read: Using Classes to Encapsulate Implementation Complexity!)
- Encapsulation - Hides object data and implementation details. Protects the state of the object from
other programs and other programs are protected from changes in implementation.
- Inheritance - Allows code reuse by building on existing classes. Using inheritance you can create
a base class
Mammaland then build on this class, creating a subclass called
Humanthat has all of the inherent properties of its base class.
- Polymorphism - Allows objects to assume many forms. For instance, we might have two classes,
Humanclass and a
Cheetahclass. Both of these objects could use the
Human.run()is called the human would run using it's two legs. When
Cheetah.run()is called the Cheetah would start running using it's four legs. They both have the
run()behavior but it can assume many forms.