Wednesday, November 12, 2008

Thinking in Layers

When creating a web application, it is very important to think in Layers.  Your web application may only have 1 layer because it is so simple, but if you plan to have more than one developer, or permit web-service access to the applicaiton, or just plan on allowing the application to grow, you should have 3-5 layers:
  1. Client - Scripts that enhance the usability of the site and run on the client interface
  2. Presentation - Objects that display the data in HTML or in a Winform
  3. Communication - Objects that expose or consume services so the application can be spread across multiple physical or virtual servers.
  4. Business Logic - Objects that contain the working data and enforce the business rules.
  5. Data Access - Objects that interact with the database
  6. Data - The database server
The manditory layers for a web application are Presentation, and Data but if you neglect to include layers in between them you will probably regret it.  

If you have a single object that interacts with the web page, enforces the business rules and interacts with the database:
  • What are you going to do when you need to expose that information via a web service?
  • What will you do if you need to optimize for performance and cache the information in a session variable?
  • Or what if you need to add another web server to handle the volume of user demand?

No comments: