473,545 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about the "Page Controller" pattern

In reading some documents from the Patterns and Practices group, I had
a question about the example given for the Page Controller pattern.
(I have posted the code for the BasePage below)
In short, their example shows a "BasePage " class for other pages to
inherit from.

The subclasses are supposed to implement the PageLoadEvent method
(which I guess should really be abstract, but can't because asp.net
won't let you inherit from a base page that is an abstract class).

Now, my question is this. I have seen many applications where the base
page, and the inheriting pages BOTH subscribe to the Load event, w/ the
Base class's event handler firing first, and then the subclasses Load
event handler.

In execution, it would work the same as what is described here, with
the only diff being that Page Controller would be intiating the Load
event on the page, rather than ASP.NET initiating the event.
Can someone explain why this matters? I guess if you were passing some
kind of information from the Page Controller to the sub class on the
PageLoadEvent method, but if you are doing just to "kick off" an event
that is already going to be kicked off by ASP.NET, what is the point?
Thanks...
Here is the Page Controller class:

using System;
using System.Web.UI;
using System.Web.UI.W ebControls;
public class BasePage : Page
{
protected Label eMail;
protected Label siteName;

virtual protected void PageLoadEvent(o bject sender, System.EventArg s e)
{}

protected void Page_Load(objec t sender, System.EventArg s e)
{
if(!IsPostBack)
{
string name = Context.User.Id entity.Name;
eMail.Text = DatabaseGateway .RetrieveAddres s(name);
siteName.Text = "Micro-site";
PageLoadEvent(s ender, e);
}
}

}

Nov 19 '05 #1
3 1759
cmay wrote:
In reading some documents from the Patterns and Practices group, I had
a question about the example given for the Page Controller pattern.
(I have posted the code for the BasePage below)
In short, their example shows a "BasePage " class for other pages to
inherit from.

The subclasses are supposed to implement the PageLoadEvent method
(which I guess should really be abstract, but can't because asp.net
won't let you inherit from a base page that is an abstract class).

Now, my question is this. I have seen many applications where the
base page, and the inheriting pages BOTH subscribe to the Load event,
w/ the Base class's event handler firing first, and then the
subclasses Load event handler.

In execution, it would work the same as what is described here, with
the only diff being that Page Controller would be intiating the Load
event on the page, rather than ASP.NET initiating the event.
Can someone explain why this matters? I guess if you were passing
some kind of information from the Page Controller to the sub class on
the PageLoadEvent method, but if you are doing just to "kick off" an
event that is already going to be kicked off by ASP.NET, what is the
point?


One reason why a base class and a derived class would subscribe to an
event is that both need to handle it without needing to know
a) that the other one handles it
and
b) how the other one handles it.
Thus there's never a requirement for a derived class to call the base
class implementation, which you must do for many framework event
handling methods (On<Event>).

But overriding methods is a dangerous thing -- you need to make sure to
fullfil the base class's expectations -- either it wants you to call
its own implementation, or it doesn't care, and in the first case you
must amke sure to call it at the correct point in time (start of
method, end of method, anywhere).

And there's no language construct to enforce either behaviour -- it's
purely driven by documentation.

This brings us to your code sample -- PageLoadEvent is a Template
Method, an extension point of a base class for modifying behaviour as a
child class sees fit.

In your BasePage example, the event handling aspect and the Template
Method server practically the same purpose, so I don't see any reason
to use both approaches at the same time.

Cheers,
--
http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e
Nov 19 '05 #2
Thanks for the reply.

I understand that you would not use both methods, but guess I am
questioning the reason for presenting this pattern for asp.net
development. (Why MS Patterns and Practices like this pattern).

It seems like you don't "gain" anything over simply using a custom base
class that doesn't bother calling a PageLoadEvent method, letting the
ASP.NET process raise that event.

Also, if you were to use the Page Controller method how could you have
an inheritance tree of more than 2 items deep? If each Page Controller
assumes that the class inheriting from it will implement the
PageLoadEvent method, wouldn't you hit a road block if you tried to
have 3 classes?

e.g. If you just build rely on ASP.NET to fire the PageLoad and catch
that at each level, then you could have:
BasePage (PageLoad does generic stuff)
SpecificFolderB asePage (PageLoad does stuff specific for its section)
EndPage (PageLoad Sets up the page)

but if you tried to do this same thing with the Page Controller, I
don't see how you could do it. In the SpecificFolderB asePage, you
would need a method PageLoadEvent to contain logic for when it is
called by BasePage, and also expect EndPage's PageLoadEvent to be fired
later, which wouldn't happen.

What I am trying to say is "SpecificFolder BasePage" and "EndPage" can't
both declare a method called PageLoadEvent have have the execution
propagate down the tree like you would need it to.

Nov 19 '05 #3
cmay wrote:
Thanks for the reply.

I understand that you would not use both methods, but guess I am
questioning the reason for presenting this pattern for asp.net
development. (Why MS Patterns and Practices like this pattern).

It seems like you don't "gain" anything over simply using a custom
base class that doesn't bother calling a PageLoadEvent method,
letting the ASP.NET process raise that event.
The sample code is somewhat contrived. They implement a base class
version of Page_Load to provide the common page header -- that's why
Template Method is used, to provide a hook for derived classes to add
their own logic without accidentally removing the page header logic.
Also, if you were to use the Page Controller method how could you have
an inheritance tree of more than 2 items deep? If each Page
Controller assumes that the class inheriting from it will implement
the PageLoadEvent method, wouldn't you hit a road block if you tried
to have 3 classes?
Yep, this may bring trouble -- you need to thoroughly document who does
what with which side-effects, or provide yet another template method...

The point here though is that deep inheritance trees are evil anyway ;-)
e.g. If you just build rely on ASP.NET to fire the PageLoad and catch
that at each level, then you could have:
BasePage (PageLoad does generic stuff)
SpecificFolderB asePage (PageLoad does stuff specific for its section)
EndPage (PageLoad Sets up the page)

but if you tried to do this same thing with the Page Controller, I
don't see how you could do it. In the SpecificFolderB asePage, you
would need a method PageLoadEvent to contain logic for when it is
called by BasePage, and also expect EndPage's PageLoadEvent to be
fired later, which wouldn't happen.

What I am trying to say is "SpecificFolder BasePage" and "EndPage"
can't both declare a method called PageLoadEvent have have the
execution propagate down the tree like you would need it to.


They can, but this leaves with you with the original problem: Do you
need to call the base class's implementation? In this situation,
Strategy is a more useful Design Pattern.

Cheers,
--
http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e
Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1872
by: The Bicycling Guitarist | last post by:
I've used and loved the webmaster tools at Delorie.com for some years now. I just added some more text content to my home page, but in the web page "purifier" the text doesn't render as I thought it should. It looks fine in MSIE 6, lol. I didn't want the text to be centered, and specified a css class to clear the floats above and text-align to...
12
1867
by: Lee David | last post by:
How do you track down this to where the error actually is? TIA, Lee
5
2294
by: Diffident | last post by:
Hello All, I have written a webform which is by default derived from "Page" class. I have coded another utility class with few methods and an object of this class is instantiated from the webfom class. Methods inside the utility class set few global variables which act as mediums of persistence to hold data. Now my question is all works...
3
11995
by: nan | last post by:
Hi All, I am trying to connect the Database which is installed in AS400 using DB2 Client Version 8 in Windows box. First i created the Catalog, then when i selected the connection type as ODBC, then i am getting
2
1289
by: Paul Wake | last post by:
Another CSS newbie question: What would be the best / most-correct-according-to-standards way to get the two photos on http://www.xmission.com/~wake/test.html to set just at the left and right edges of the white "page" so that the fingers overlap the "page?" (They're just test photos at the moment; if I do this for real I'll use better...
33
2321
by: STILL LEARNING | last post by:
I'm not sure if this can even be done, but what prompts the question is my desire to be able to create an "Uber Link" script/code of some sort, such that even if the html page contains nothing but a background image -or- a background color -- in other words, the page has neither content nor placed images -- any click, ANYWHERE, will launch...
4
3084
by: lander | last post by:
I've read the page life cycle thing in msdn, still, i'm getting a bit confused of thinking how all the things are going under the hood... I know that when page loading, that the controls' properties is populated and when page unloading, the resources are cleared. What I want to know is what's happening behind it, that is, from the...
6
7994
by: James Yang | last post by:
"bad page", especially in table, is a risk for database maintenance. The particular access attempt for corrupt blocks may not occur often, and corrupt DB2 blocks are not recognized during a database backup, corrupt blocks can remain undetected in an UDB system for a long time. The potential solution is: 1) Restore from a GOOD backup and...
0
7464
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7396
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.