Most of the applications we’ve looked at in this book have been two-tier, separating the user interface from the backend data. Many larger commercial applications, however, are n-tier, with at least a middle business-logic layer to separate retrieval of data from the database from manipulation (and validation) of that data before presentation.
In Chapter 7, you saw how you can use the
ObjectDataSource to reference a class that provides the data to be presented on the page. Taking this example one step further, you can create a simple Model-View-Controller (MVC) style designed site which uses a stateless class to encapsulate business logic, and a “model” class that knows how to load and store data from the database.
To illustrate implementing the n-tier MVC pattern, you’ll create a stateless business class,
CustomerBusinessLogic, and a “model” of the
Customer table in the AdventureWorksLT database, named
AWCustomer. You’ll bind an
ObjectDataSource to the stateless business-logic class, which will use the
Model class to get and retrieve data about customers in the database.
This is a much simplified example of the MVC model made to fit within a few pages of a book. Fully fledged MVC site templates are available to download for almost all languages. Ruby on Rails is the most well-known example, but Microsoft is also working on its own MVC site templates for Visual Studio development. See Chapter 21 for more information on that.
To begin, add a new class called ...