Export (0) Print
Expand All

Design and Implementation Guidelines for Web Clients

Retired Content
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
 

patterns & practices Developer Center

Microsoft Corporation

November 2003

Applies to:
   Microsoft .NET Framework
   ASP.NET

Summary: Introduces the topics in this guide and provides guidance on basic terminology. It also notes the decisions the authors of this guide assume you have already made. Additionally, this chapter summarizes the key messages that are documented in detail elsewhere in this guide and describes how this guide fits into the Microsoft patterns & practices family of documentation.

Contents

Introduction

How To Use This Guide

Defining the Presentation Layer

Summary

Introduction

Most, if not all, applications require some level of user interaction. In today's distributed applications, the code that manages this user interaction is in the presentation layer.

Most simple presentation layers contain user interface components, such as Microsoft® Windows Forms or ASP.NET Web Forms. These components typically contain code to perform functions such as configuring the visual appearance of controls; accepting and validating user input; and acquiring and rendering data from data access logic components or business components.

The presentation layer can also include user interface process components. User interface process components perform presentation layer tasks that are not directly concerned with user interactions. For example, user interface process components orchestrate the flow of control between forms in the presentation layer and coordinate background tasks such as state management and handling of concurrent user activities.

Design and Implementation Guidelines for Web Clients provides advice on how best to implement logic in the presentation layer of a distributed application. This guide is designed to accompany the User Interface Process Application Block; this application block provides a template implementation for user interface process components. For more information about how and when to use this block, see Chapter 2, "Using Design Patterns in the Presentation Layer," in this guide. For more information about the application block, including download information, see User Interface Process Application Block Overview on MSDN® (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/uip.asp).

How To Use This Guide

This guide addresses specific goals of presentation layer component design. This guide provides prescriptive recommendations and code samples that enable you to use design patterns and Microsoft .NET Framework programming idioms effectively in the presentation layer of your applications. The intent of this guide is to help you increase the portability, maintainability, scalability, security, and overall design quality of your presentation layer code; it does not discuss aesthetic user interface design issues.

The information in this guide is organized into the following chapters:

  • This chapter introduces the topics in this guide and provides guidance on basic terminology. It also notes the decisions the authors of this guide assume you have already made.

    Additionally, this chapter summarizes the key messages that are documented in detail elsewhere in this guide and describes how this guide fits into the Microsoft patterns & practices family of documentation.

  • Chapter 2, "Using Design Patterns in the Presentation Layer," describes how to separate the responsibilities of components in the presentation layers by using common design patterns.

    Design patterns help you get a clean separation between the code that presents data to the user and accepts user interactions and the code that orchestrates the flow of control between forms and handles issues such as state management, data access, and asynchronous behavior in the presentation layer. By partitioning your code in this way, you can reduce the coupling between the various parts of your application, and thereby make your code easier to change and extend as requirements evolve.

    Chapter 2 introduces a template implementation of the key design patterns. The template is included in the User Interface Process Application Block. Chapter 2 describes how to use this block as the basis for your own user interface code, thereby realizing the benefits described in the previous paragraph.

  • Chapter 3, "Building Maintainable Web Interfaces with ASP.NET," describes how to make ASP.NET code easier to implement and maintain. This chapter describes how to use custom controls to share specific behavior across multiple controls and how to use common page layouts to ensure there is a common appearance across all the pages in your Web site. This chapter also describes how to use inheritance appropriately and effectively in Web applications in order to reuse controls in the presentation layer.
  • Chapter 4, "Managing Data," describes the correct way for components in the user interface (UI) to access, present, update, and validate data input, and how the UI participates in maintaining data integrity.

    The first of these topics, "Accessing and Representing Data," compares and contrasts various techniques for accessing data in the presentation layer. This topic describes the best way to represent data in disconnected and streaming applications and how best to use transactions in the presentation layer. This topic also describes the importance of a layered approach to data access and how to use message-driven techniques, data access logic components, and business objects to access data in specific scenarios.

    The second topic in the chapter, "Presenting Data Using Formatters, Data Binding, and Paging," describes how to use .NET Framework formatter classes, data binding techniques, and paging to display data to the user.

    The third topic in the chapter, "Supporting Data Updates from the Presentation Layer," describes how the presentation layer can participate in updates to data in a back-end data store such as a relational database. This topic describes how to create data maintenance forms that let users create, read, update, and delete data entities either individually or as part of a list. It also describes how to increase productivity by implementing metadata-based forms that are sufficiently flexible to handle data in any structure.

    The final topic in the chapter, "Validating Data in the Presentation Layer," describes scenarios where data validation is appropriate in the presentation layer. The presentation layer is the first line of defense against accidental or malicious rogue data from the user. This topic describes how and when to use .NET Framework validator controls to validate the format and content of input data and includes strategies for handling validation failures.

  • Chapter 5, "Managing State in Web Applications," describes the types of state used in the presentation layer and offers guidance about how to manage state in applications written for the Web. Correct state management is critical to the scalability and availability of Web applications.

    For Web applications, this chapter discusses the pros and cons of storing per-user session data in the in-process Session object, the state server-based Session object, or the SQL Server™-based Session object. This chapter also discusses how to use cookies, hidden form fields, URL rewiring, and the ASP.NET ViewState property as alternative ways to maintain state between pages in an ASP.NET Web application. Finally, it discusses how to use the Application object to share state between all users and sessions of an application.

  • Chapter 6, "Multithreading and Asynchronous Programming in Web Applications," describes how to increase performance and responsiveness of the code in the presentation layer by using multithreading and asynchronous programming.

    This chapter describes how to use .NET Framework thread pools to simplify multithreaded code in your application. In situations where the thread pool is inappropriate, the chapter describes how to manually create, manage, and synchronize threads in your code.

    This chapter also describes how and when to use asynchronous method invocation, by using delegates. Delegates represent method calls on objects; with delegates, you can start methods asynchronously by using the BeginInvoke and EndInvoke delegate methods.

  • Chapter 7, "Globalization and Localization," describes how globalization and localization requirements affect the development of your presentation layers.

    This chapter addresses how the .NET Framework uses cultures to define language-specific and country-specific issues, such as number formats and currency symbols; it also describes how and when it might be useful to define alternative cultures programmatically.

    Additionally, this chapter describes how to format various .NET Framework data types appropriately, according to the current culture. As part of this discussion, it describes how to create custom resource files to hold language-specific string resources and images.

  • Appendix A, "Securing and Operating the Presentation Layer," describes how security and manageability considerations affect the design of presentation layer components.

    This appendix reviews the importance of authentication and authorization in the presentation layer and the options available for performing these tasks in various circumstances. Additionally, it describes how to improve the security of communications using Secure Sockets Layer (SSL), Internet Protocol Security (IPSec), and Virtual Private Networking (VPN).

    This appendix also describes operational management issues as they pertain to the presentation layer. It describes how to manage exceptions in the presentation layer; health monitoring; and performance monitoring.

  • Appendix B, "How To Samples," provides code samples to illustrate the various techniques described throughout this guide.

The next section defines the types of components that the presentation layer contains; it also describes how this guide fits into the broader family of Microsoft patterns & practices guides.

Defining the Presentation Layer

For architectural- and design-level guidance about creating layered, distributed applications, see Application Architecture for .NET: Designing Applications and Services on MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/distapp.asp). It defines the application architecture illustrated in Figure 1.1.

Ff647339.f01diforwc01(en-us,PandP.10).gif

Figure 1.1. Application architecture

The presentation layer includes the following types of software components that perform specific tasks:

  • User interface components–These components make up the user interface of the application. Users see and interact with these components.
  • User interface process components–These components orchestrate the user interface elements and control user interaction. Users do not see user interface process components; however, these components perform a vital supportive role to user interface components.

The combination of these two types of components forms the presentation layer of the application. The presentation layer interoperates with the business and data access layers to form the overall solution. The following section outlines the typical responsibility for each kind of component in the presentation layer and explains the benefits for dividing the presentation layer as described.

Defining User Interface Components

User interface components make up the subset of presentation layer components that interact with the user. You can think of it as a layer in itself. They are generally referred to as "views" in presentation design patterns. User interface components are responsible for:

  • Acquiring data from the user
  • Rendering data to the user

The following characteristics determine other responsibilities for user interface components:

  • Validation, input masking, and using appropriate controls for data input
  • Managing visual layouts, styles, and the general appearance and navigation of the application
  • Encapsulating the affect of globalization and localization
  • Formatting data and displaying it in useful visual styles
  • Browsing, searching, and organizing displayed data

Common user interface choices include:

  • Console applications–This approach is suitable for simple utilities that can easily be controlled from a command line.
  • Windows Forms-based applications–Windows Forms-based user interfaces are the preferred choice for rich client applications that are deployed on desktop, laptop, and tablet PCs.
  • Microsoft Office VBA solutions–In environments where Microsoft Office applications are used extensively, it can frequently be appropriate to build custom Office-based solutions that allow users to perform business tasks from familiar applications.
  • .NET Compact Framework applications–The .NET Framework 1.1 includes a subset of classes suitable for building applications for smart devices such as Pocket PCs and Smartphones. This approach can be used to develop rich user interfaces for mobile devices.
  • ASP.NET Web applications–When an application must be accessible across an intranet or Internet connection, it is a good idea to use ASP.NET to create a Web application hosted in Internet Information Services (IIS). ASP.NET makes it possible to build complex user interfaces that transcend many of the limitations of conventional static HTML and script-based Web solutions.
  • ASP.NET mobile Web applications–The .NET Framework 1.1 includes ASP.NET-based controls specifically targeted at mobile devices such as Personal Digital Assistants (PDAs) and Wireless Application Protocol (WAP)-enabled mobile phones. These controls are dynamically rendered in a format appropriate to the device being used to access the application, and therefore make it possible to build Web applications for a broad spectrum of mobile devices.
  • Speech-enabled applications–The Microsoft .NET Speech SDK makes it possible to build applications that respond to voice input. When combined with Microsoft Speech Server, the .NET Speech SDK makes it possible to build voice-driven telephony solutions with a wide range of applications. Beta 3 of the .NET Speech SDK is currently available. For more information about speech-enabled application development, see the Microsoft Speech Technologies Web site (http://www.microsoft.com/speech/speech2007/default.mspx).

Regardless of the specific technology used to implement them, user interface components are used to present information to the user and to accept user input, thereby enabling interaction with the business process embodied in the application.

Defining User Interface Process Components

The user interface components described in the preceding section manage data rendering and acquisition with the user, but these responsibilities do not cover the full spectrum of issues that presentation layers must handle.

A user interacts with an application executing use cases. Each use case requires a set of interactions with the user and the business layers to complete. Applications that have use cases involving multiple user interface components, or that have to implement multiple user interfaces, have to decide how to maintain data or state across all user interactions and how the user control flows across multiple user interface components.

User interface process components are responsible for managing interactions between multiple user interactions in a use case. User interface process components are referred to as application controllers in design pattern terminology.

User interface process components are responsible for:

  • Managing control flow through the user interface components involved in a use case
  • Encapsulating how exceptions affect the user process flow
  • Separating the conceptual user interaction flow from the implementation or device where it occurs
  • Maintaining internal business-related state, usually holding on to one or more business entities that are affected by the user interaction

This means they also manage:

  • Accumulating data taken from many UI components to perform a batch update
  • Keeping track of the progress of a user in a certain process
  • Exposing functionality that user interface components can invoke to receive data they must render to affect the state for the process

To help you separate the tasks performed by user interface process components from the tasks performed by user interface components, follow these guidelines:

  • Identify the business process or processes that the user interface process helps to accomplish. Identify how the user sees this as a task.
  • Identify the data needed by the business processes. The user process needs to be able to submit this data when necessary.
  • Identify additional state you need to maintain throughout the user activity to assist rendering and data capture in the user interface.

The User Interface Process Application Block provides a template implementation for user interface process components. For more information about how to use this block, see Chapter 2, "Using Design Patterns in the Presentation Layer."

Additional Information

For more information about the full range of available patterns & practices guides and application blocks, see the patterns & practices Web site (http://msdn.microsoft.com/en-us/practices/default.aspx).

The following guides provide guidance and background information about how to implement the other tiers in the recommended application architecture:

  • .NET Data Access Architecture Guide

    This guide provides guidelines for implementing an ADO.NET-based data access layer in a multi-tiered .NET Framework application. It focuses on a range of common data access tasks and scenarios and presents guidance to help you choose the most appropriate approaches and techniques. For more information about this guide, including download information, see.NET Data Access Architecture Guide on MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daag.asp).

  • Designing Data Tier Components and Passing Data Through Tiers

    This guide covers data access and representation of business data in a distributed application and provides guidance to help you choose the most appropriate way to expose, persist, and pass data through the application tiers. For more information about this guide, including download information, see Designing Data Tier Components and Passing Data Through Tiers on MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/BOAGag.asp).

  • Web Service Faç ;ade for Legacy Applications

    This guide defines best practices for interfacing with COM-based applications by using XML Web services created using ASP.NET and the Microsoft .NET Framework. For more information about this guide, including download information, see Web Service Façade for Legacy Applications on MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/wsfacadelegacyapp.asp).

Summary

Presentation layer components provide the user interface that users use to interact with the application. Presentation layer components also perform user interface process management to orchestrate those interactions. All applications require a presentation layer of some kind, and when designing a solution, you must consider the architectural issues relating to the presentation layer of your particular application.

The rest of this guide reviews the architectural issues relating to presentation layer development.

Start | Previous | Next

patterns & practices Developer Center

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Show:
© 2014 Microsoft