Google Apps, hosted software. Learn More.


Click to Play

PubCon: Rand Fishkin of SEOmoz
WebProNews spoke with Rand Fishkin, the CEO and Co-Founder of SEOmoz.org, at PubCon Las Vegas 2007. Fishkin discusses the prevalence of link buying. He....

Recent Articles

Using Robust Exception Information On A Shared Host
I was recently contacted by a possible client who was looking for a code review. As part of my standard "playing around" I noticed that his site was throwing errors with the full path information revealed. As folks know, I always recommend you turn off Show...

Application.cfc Methods & Example Uses
A reader commented yesterday that my Application.cfc reference doesn't really say how to use the various methods. Since my reference is intended to be a simple code skeleton, I thought I'd quickly explain each...

DirectoryWatcher & ColdFusion Image Manipulation
Now that ColdFusion 8 gives us a crap load of image functions as well as event gateways in all editions, I thought I'd write up a super quick demo on how you can use both in your application. If you've never played with event gateways before, either because you thought...

Using Spry:hover, Spry:even, & Spry:odd All Together
One of the nicer features of Spry is the simple way you can apply even, odd, and hover classes to a dataset. This code will tell Spry to apply a CSS class named even for even rows, odd for odd rows, and to notice...

Yahoo Strategy Includes Attracting More Developers
Yahoo's old founder and new boss, Jerry Yang, outlined where the company is heading now in a blog post yesterday. The three key items he sees after talking things through with people in the company are "Become the starting point for the most consumers."...

AJAX - Too Much Choice
Last week I spoke with Todd Hay, VP of Marketing at ActiveGrid. "Too often, we fight ourselves in the AJAX community. For customers, there is too much confusion between AJAX libraries such as Dojo, JQuery...


Sign Up For adCenter - Get $50 In Free* Clicks.
12.17.07


Structuring Web Apps Into Multiple Tiers

By Mads Kristensen

Very often I read that you need to structure your web applications into multiple tiers to separate the concerns.

The advice is to move the business and data logic out of the web project into two different projects so you end up with the classic 3 tier model - presentation, business and data. This advice is good.

The strange thing is that this advice is given to web developers as a way of structuring web applications. I've always found that very odd. Not that web developers don't write business and data logic, but I don't see the connection between web development and business/data logic development.
Let me explain

The premise for the advice is that business/data logic is part of building a website. This is wrong. A website is a visual representation that interacts with the business logic, but the business logic doesn't and shouldn't care about the website. The business logic is an API consumed by the website and nothing more. The business logic still doesn't care if its public methods (API) are used on a website, in a Windows Forms application or in a web service. Ergo, business logic is not part of building a website. The premise is wrong.

In a typical 3 tier web solution you have three projects - the website, business- and data logic projects. That makes it a little confusing to believe that the business and data logic has nothing to do with building a website. But if you think of the three projects as the building blocks in creating a solution then it's easier to understand. In other words; you don't separate a website into three tiers by separating the business and data logic into their own projects, you separate the solution into three tiers. Since the website is just the UI in such a solution, it is wrong statement that your website is 3-tiered and the premise is then wrong.
The three tiers

The reason why I've always found this advice odd is that I always build my websites in three tiers, but it has nothing to do with the business and data logic. The three tiers I use in web development are specific for the website only. The tiers are:

1. User interface
2. User interface logic
3. Presentation logic

The names are just some that I use and may be different elsewhere.

Google Apps, hosted software. Learn More.

User interface (UI)

The UI is the HTML, JavaScript and CSS that makes up the visual look and feel and the browser behavior. It lives in pages (.aspx), user controls (.ascx), .js and .css files. In some cases also in HTTP handlers (.ashx), but mainly for custom AJAX mechanisms.

User interface logic

This tier is what controls the server side behaviour of the UI. It lives in code-behind files and in the App_Code folder. This logic is responsible for handling button events and differentiates the response based on the user etc. It's also custom web control collections that could live in its own project and often do.
Presentation logic

This is the where all the stuff goes that isn't directly is used in the UI. It could be RSS feeds or classes used by the code-behind. Most often it's where I put the HttpHandlers and HttpModules and the logic that controls them. It could be located in its own project or it could just be in its own folder in the App_Code or wherever it feels right to put it depending on the size of the project.

It doesn't really matter where the tiers are physically placed as long as they are logically separated. That's why it often makes sense to move the tiers into their own projects to make the separation clear and the code easier to maintain and reuse.

So a three tier web application has nothing to do with business and data logic. Remember that the business logic is just an API consumed by a website even if they both live in the same Visual Studio solution.

Comments


About the Author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

About TheDevWeb
TheDevWeb examines the best tools and techniques to help you keep up with all the latest trends in the fast paced world of web development. Excellence in Development Starts Here

TheDevWeb is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITmanagementNews.com



-- TheDevWeb is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2007 iEntry, Inc. All Rights Reserved Privacy Policy Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article



Excellence in Development Starts Here TheDevWeb News Archives About Us Feedback TheDevWeb Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact