Saturday, October 27, 2007

The WebNavigator

What is the Web Navigator?!
Well the Web Navigator is a techhnique, or pattern that I was introduced to from a podcast by Craig Shoemaker at "Download example code"This pattern is a great way of creating Contracts for Your Web Pages, so its much easier to manage navigation throughout your websites.Some of the strength that i like about it, is that it "Encapsulate page locations" , "Makes the code easy to read and maintain" and make contract of a page requirements.

The Code
Lets say that you need to se a profile page, and that page show userinfo by a querystring, the code could look like this.string userName;
// set userName to something... perhaps from the database

class WebNavigator
public void GoTo(string url)
public string Profile(string userName)
return string.Format("~/login/default.aspx?userName={0}",userName);

You could make it more dynamically so you dont have to recompile if the url changes, by store the urls in xml or whatever you like.
In umbraco the method could look like this.

public string Profile(string userName) { return umbraco.library.GetDictionaryItem("ProfileUrl") + "?" + userName);

No comments:

Post a Comment