Published: Monday, September 18, 2000
Using Object-Orientation in ASP.NET : Overview
By 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#.
This article is intended to show the power of OO and how it can be applied in ASP.NET to create reusable, robust,
simpler, and flexible applications. This is a four part series, covering all the basics of OO, showing
examples in C#. If you don't know C# don't worry, It's similar in syntax to JavaScript, and I have made the
examples as simple and clear as possible. So you should be able to pick them up pretty easily.
(To learn more about C#, be sure to check out our C# Article Index!)
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
Concepts Overview
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
Human class 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
Mammal and then build on this class, creating a subclass called Human that has all of the
inherent properties of its base class.
- Polymorphism - Allows objects to assume many forms. For instance, we might have two classes,
a
Human class and a Cheetah class. Both of these objects could use the run() behavior. When
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.
Links:
Using Classes to Encapsulate Implementation Complexity
Basic Object-Oriented Concepts
Object-Orientation FAQ
*** Read The Second Part of this Four Part Series: Using Object-Orientation in ASP.NET : Encapsulation***
Happy Programming!
By Ian Stallings