I understand about what classes are, my confusion is in why
having a page as an explicitly declared class is an advantage.
Whoa, Alan, you lost me there. Did you notice that I said "everything in
..Net is a class"? It doesn't matter whether you "explicitly declare" it as
such (whatever that means). It is what it is.
As I said, I can see that writing your own classes to represent objects
(like an order object in a sales system) makes sense as you wrap the data
and methods into one object. My question is, given that the page is really
the top level object that you see in ASP.NET, what advantage do you have
if you explicitly create that class, or the runtime creates it implicitly
from your coding? Either way you end up with a class which you don't
really use. Your code is inside the class and works on objects further
down the hierarchy. Who care how the parent object was created?
You end up with a class that you don't really use? What do you think is
creating the Response? Your Page class. And System.Web.UI.Page is hardly a
"top-level" class (whatever that means). It is simply a class, like any
other, and it implements IHttpHandler, just like any other IHttpHandler.
Why do you have to write it as a class? Well, remember that "in .Net
everything is a class." What are you going to type all your code into? A
class declaration. Why does System.Web.UI.Page exist? As a base class from
which you can derive as many ASPX page classes as your apps need. Do you
have to use it? No. You can use any IHttpHandler, even one you create
yourself. Why do you inherit it? Bacause you don't want to have to ype in
all the underlying code in the class every time you create a new Page.
That's what Inheritance is for.
Note: If you think your class is just the code that you add to your template
or Code-behind, you're much mistaken. The base System.Web.UI.Page class has
a whole slew of properties, fields, and methods that all exist because you
simply inherit it. They don't show up in your template; they are part of the
base class. You just type in "Inherits System.Web.UI.Page" and -BAM!- it IS
a System.Web.UI.Page that you can now extend without even apparently
realizing it.
ASP Classic, on the other hand, is not OOP, and you can't simply inherit a
bunch of functionality and build on it. Every ASP page is unique. You code
it from the ground up. If you have common functionality, the only way to
include it is using server-side includes. Server-side includes are
procedural as well, and BTW, when you use server-side includes, every page
has its own instance of the include when it runs. The included code is added
to the page code just prior to compilation. This sort of issue was why OOP
was created.
Does that help?
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.