You are previewing Professional ASP.NET Design Patterns.
O'Reilly logo
Professional ASP.NET Design Patterns

Book Description

Professional ASP.NET Design Patterns will show you how to implement design patterns in real ASP.NET applications by introducing you to the basic OOP skills needed to understand and interpret design patterns. A sample application used throughout the book is an enterprise level ASP.NET website with multi-tiered, SOA design techniques that can be applied to your future ASP.NET projects. Read about each design pattern in detail, including how to interpret the UML design, how to implement it in ASP.NET, its importance for ASP.NET development, and how it's integrated into the final project.

Table of Contents

  1. Copyright
  2. ABOUT THE AUTHOR
  3. CREDITS
  4. ACKNOWLEDGMENTS
  5. FOREWORD
  6. INTRODUCTION
    1. WHO THIS BOOK IS FOR
    2. WHAT THIS BOOK COVERS
    3. HOW THIS BOOK IS STRUCTURED
      1. Part 1: Introducing Patterns and Principles
        1. Chapter 1: The Pattern for Successful Applications
        2. Chapter 2: Dissecting the Pattern's Pattern
      2. Part 2: The Anatomy of an ASP.NET Application: Learning and Applying Patterns
        1. Chapter 3: Layering Your Application and Separating Your Concerns
        2. Chapter 4: The Business Logic Layer: Organization
        3. Chapter 5: The Business Logic Layer: Patterns
        4. Chapter 6: The Service Layer
        5. Chapter 7: The Data Access Layer
        6. Chapter 8: The Presentation Layer
        7. Chapter 9: The User Experience Layer
      3. Part 3: Case Study: The Online E-Commerce Store
        1. Chapter 10: Requirements and Infrastructure
        2. Chapter 11: Creating the Product Catalog
        3. Chapter 12: Implementing the Shopping Basket
        4. Chapter 13: Customer Membership
        5. Chapter 14: Ordering and Payment
    4. CONVENTIONS
    5. SOURCE CODE
    6. ERRATA
    7. P2P.WROX.COM
  7. I. Introducing Patterns and Principles
    1. 1. The Pattern for Successful Applications
      1. 1.1. DESIGN PATTERNS EXPLAINED
        1. 1.1.1. Origins
        2. 1.1.2. Necessity
        3. 1.1.3. Usefulness
        4. 1.1.4. What They Are Not
      2. 1.2. DESIGN PRINCIPLES
        1. 1.2.1. Common Design Principles
          1. 1.2.1.1. Keep It Simple Stupid (KISS)
          2. 1.2.1.2. Don't Repeat Yourself (DRY)
          3. 1.2.1.3. Tell, Don't Ask
          4. 1.2.1.4. You Ain't Gonna Need It (YAGNI)
          5. 1.2.1.5. Separation of Concerns (SoC)
        2. 1.2.2. The S.O.L.I.D. Design Principles
          1. 1.2.2.1. Single Responsibility Principle (SRP)
          2. 1.2.2.2. Open-Closed Principle (OCP)
          3. 1.2.2.3. Liskov Substitution Principle (LSP)
          4. 1.2.2.4. Interface Segregation Principle (ISP)
          5. 1.2.2.5. Dependency Inversion Principle (DIP)
          6. 1.2.2.6. Dependency Injection (DI) and Inversion of Control (IoC)
      3. 1.3. FOWLER'S ENTERPRISE DESIGN PATTERNS
        1. 1.3.1. Layering
        2. 1.3.2. Domain Logic Patterns
          1. 1.3.2.1. Transaction Script
          2. 1.3.2.2. Active Record
          3. 1.3.2.3. Domain Model
        3. 1.3.3. Object Relational Mapping
          1. 1.3.3.1. Unit of Work
          2. 1.3.3.2. Repository
          3. 1.3.3.3. Data Mapper
          4. 1.3.3.4. Identity Map
          5. 1.3.3.5. Lazy Loading
          6. 1.3.3.6. Query Object
        4. 1.3.4. Web Presentation Patterns
        5. 1.3.5. Base, Behavioral, and Structural Patterns
          1. 1.3.5.1. Null Object Pattern
          2. 1.3.5.2. Separated Interface
          3. 1.3.5.3. Gateway
      4. 1.4. OTHER DESIGN PRACTICES OF NOTE
        1. 1.4.1. Test-driven Development (TDD)
        2. 1.4.2. Domain-driven Design (DDD)
        3. 1.4.3. Behavior-driven Design (BDD)
      5. 1.5. SUMMARY
    2. 2. Dissecting the Pattern's Pattern
      1. 2.1. HOW TO READ DESIGN PATTERNS
        1. 2.1.1. Gang of Four Pattern Template
        2. 2.1.2. Simplified Template
          1. 2.1.2.1. Name and Intent
          2. 2.1.2.2. UML Diagram
          3. 2.1.2.3. Code Example
      2. 2.2. DESIGN PATTERN GROUPS
        1. 2.2.1. Creational
        2. 2.2.2. Structural
        3. 2.2.3. Behavioral
      3. 2.3. HOW TO CHOOSE AND APPLY A DESIGN PATTERN
      4. 2.4. A QUICK PATTERN EXAMPLE
        1. 2.4.1. Refactoring to Principles
          1. 2.4.1.1. The Dependency Inversion Principle
          2. 2.4.1.2. The Dependency Injection Principle
        2. 2.4.2. Refactoring to the Adapter Pattern
        3. 2.4.3. Leveraging Enterprise Patterns
          1. 2.4.3.1. Null Object Pattern
      5. 2.5. SUMMARY
  8. II. The Anatomy of an ASP.NET Application: Learning and Applying Patterns
    1. 3. Layering Your Application and Separating Your Concerns
      1. 3.1. APPLICATION ARCHITECTURE AND DESIGN
        1. 3.1.1. Antipattern — Smart UI
        2. 3.1.2. Separating Your Concerns
          1. 3.1.2.1. Business Layer
          2. 3.1.2.2. Service Layer
          3. 3.1.2.3. Data Access Layer
          4. 3.1.2.4. Presentation Layer
          5. 3.1.2.5. User Experience Layer
      2. 3.2. SUMMARY
    2. 4. The Business Logic Layer: Organization
      1. 4.1. UNDERSTANDING BUSINESS ORGANIZATIONAL PATTERNS
        1. 4.1.1. Transaction Script
        2. 4.1.2. Active Record
        3. 4.1.3. Domain Model
          1. 4.1.3.1. POCO and PI
          2. 4.1.3.2. Code Example
        4. 4.1.4. Anemic Domain Model
        5. 4.1.5. Domain-Driven Design
          1. 4.1.5.1. The Ubiquitous Language
          2. 4.1.5.2. Entities
          3. 4.1.5.3. Value Objects
          4. 4.1.5.4. Aggregates and Aggregate Roots
          5. 4.1.5.5. Domain Services
          6. 4.1.5.6. Application Services
          7. 4.1.5.7. Repository
          8. 4.1.5.8. Layering
      2. 4.2. SUMMARY
    3. 5. The Business Logic Layer: Patterns
      1. 5.1. LEVERAGING DESIGN PATTERNS
        1. 5.1.1. Factory Method
          1. 5.1.1.1. Intent
          2. 5.1.1.2. UML
          3. 5.1.1.3. Code Example
        2. 5.1.2. Decorator
          1. 5.1.2.1. Intent
          2. 5.1.2.2. UML
          3. 5.1.2.3. Code Example
        3. 5.1.3. Template Method
          1. 5.1.3.1. Intent
          2. 5.1.3.2. UML
          3. 5.1.3.3. Code Example
        4. 5.1.4. State Pattern
          1. 5.1.4.1. Intent
          2. 5.1.4.2. UML
          3. 5.1.4.3. Code Example
        5. 5.1.5. Strategy
          1. 5.1.5.1. Intent
          2. 5.1.5.2. UML
          3. 5.1.5.3. Code Example
      2. 5.2. LEVERAGING ENTERPRISE PATTERNS
        1. 5.2.1. Specification Pattern
          1. 5.2.1.1. Intent
          2. 5.2.1.2. Code Example
        2. 5.2.2. Composite Pattern
          1. 5.2.2.1. Intent
          2. 5.2.2.2. UML
          3. 5.2.2.3. Code Example
        3. 5.2.3. Layer Supertype Pattern
          1. 5.2.3.1. Intent
          2. 5.2.3.2. Code Example
      3. 5.3. APPLYING DESIGN PRINCIPLES
        1. 5.3.1. Dependency Inversion Principle and the Dependency Injection Pattern
          1. 5.3.1.1. Intent
          2. 5.3.1.2. Code Example
        2. 5.3.2. Interface Segregation Principle
          1. 5.3.2.1. Intent
          2. 5.3.2.2. Code Example
        3. 5.3.3. Liskov Substitution Principle
          1. 5.3.3.1. Intent
          2. 5.3.3.2. Code Example
      4. 5.4. SUMMARY
    4. 6. The Service Layer
      1. 6.1. DESCRIBING THE SERVICE LAYER
        1. 6.1.1. Service Oriented Architecture
        2. 6.1.2. Four Tenets of SOA
          1. 6.1.2.1. Boundaries Are Explicit
          2. 6.1.2.2. Services Are Autonomous
          3. 6.1.2.3. Services Share Schema and Contract, Not Class
          4. 6.1.2.4. Service Compatibility Is Based on Policy
        3. 6.1.3. The Facade Design Pattern
          1. 6.1.3.1. Intent
          2. 6.1.3.2. UML
      2. 6.2. LEVERAGING MESSAGING PATTERNS
        1. 6.2.1. The Document Message and the Request-Response Patterns
        2. 6.2.2. The Reservation Pattern
        3. 6.2.3. The Idempotent Pattern
      3. 6.3. AN SOA EXAMPLE
        1. 6.3.1. Domain Model and Repository
        2. 6.3.2. Service Layer
        3. 6.3.3. Client Proxy
        4. 6.3.4. Client
      4. 6.4. SUMMARY
    5. 7. The Data Access Layer
      1. 7.1. DESCRIBING THE DAL
      2. 7.2. DATA ACCESS STRATEGIES
        1. 7.2.1. The Repository Pattern
        2. 7.2.2. Data Access Objects Pattern
      3. 7.3. PATTERNS IN DATA ACCESS
        1. 7.3.1. Unit of Work
        2. 7.3.2. Data Concurrency Control
        3. 7.3.3. Lazy Loading and the Proxy Pattern
          1. 7.3.3.1. Intent
          2. 7.3.3.2. UML
          3. 7.3.3.3. Code Example
        4. 7.3.4. Identity Map
        5. 7.3.5. Query Object Pattern
      4. 7.4. USING AN OBJECT RELATIONAL MAPPER
        1. 7.4.1. NHibernate
        2. 7.4.2. MS Entity Framework
        3. 7.4.3. ORM Code Example
          1. 7.4.3.1. Library Domain Model
          2. 7.4.3.2. The Service Layer
          3. 7.4.3.3. Database
          4. 7.4.3.4. NHibernate Repository
          5. 7.4.3.5. Entity Framework Repository
          6. 7.4.3.6. Presentation
          7. 7.4.3.7. Raw ADO.NET Repository
      5. 7.5. SUMMARY
    6. 8. The Presentation Layer
      1. 8.1. INVERSION OF CONTROL
        1. 8.1.1. Factory Design Pattern
        2. 8.1.2. Service Locator
        3. 8.1.3. IoC Containers
          1. 8.1.3.1. StructureMap
      2. 8.2. MODEL-VIEW-PRESENTER
        1. 8.2.1. ASP.NET Web Forms with MVP
      3. 8.3. FRONT CONTROLLER
        1. 8.3.1. Command Pattern
          1. 8.3.1.1. Intent
          2. 8.3.1.2. UML
          3. 8.3.1.3. Code Example
        2. 8.3.2. Chain of Responsibility Pattern
          1. 8.3.2.1. Intent
          2. 8.3.2.2. UML
          3. 8.3.2.3. Code Example
      4. 8.4. MODEL-VIEW-CONTROLLER
        1. 8.4.1. ViewModel Pattern
        2. 8.4.2. The ASP.NET MVC Framework
          1. 8.4.2.1. Mapping ViewModels with AutoMapper
        3. 8.4.3. Castle MonoRail
      5. 8.5. PAGE CONTROLLER
      6. 8.6. SUMMARY
    7. 9. The User Experience Layer
      1. 9.1. WHAT IS AJAX?
      2. 9.2. USING JAVASCRIPT LIBRARIES
      3. 9.3. UNDERSTANDING AJAX PATTERNS
        1. 9.3.1. Periodic Refresh and Timeout
          1. 9.3.1.1. Periodic Refresh and Timeout Pattern Code Example
          2. 9.3.1.2. Periodic Refresh Implementation Script
          3. 9.3.1.3. Timeout Pattern Implementation Script
          4. 9.3.1.4. Using Firefox and Firebug for Web Development
        2. 9.3.2. Unique URL
        3. 9.3.3. Databinding with JavaScript Templates
          1. 9.3.3.1. History and Templates Code Example
        4. 9.3.4. Predictive Fetch
          1. 9.3.4.1. Predictive Fetch Code Example
      4. 9.4. SUMMARY
  9. III. Case Study: The Online E-Commerce Store
    1. 10. Requirements and Infrastructure
      1. 10.1. AGATHA'S CLOTHING STORE REQUIREMENTS
        1. 10.1.1. Product Catalog and Basket Screens
        2. 10.1.2. Customer Account Screens
        3. 10.1.3. Checkout Screens
        4. 10.1.4. Caching and Logging
      2. 10.2. ARCHITECTURE
        1. 10.2.1. Setting Up the Supporting Infrastructure
          1. 10.2.1.1. Domain Layer Supertype
          2. 10.2.1.2. Unit of Work Pattern
          3. 10.2.1.3. Query Object Pattern
          4. 10.2.1.4. Application Configuration Settings
          5. 10.2.1.5. Logging
          6. 10.2.1.6. E-Mail Service
          7. 10.2.1.7. Helper Classes
      3. 10.3. SUMMARY
    2. 11. Creating The Product Catalog
      1. 11.1. CREATING THE PRODUCT CATALOG
        1. 11.1.1. Product Catalog Model
        2. 11.1.2. Product Catalog Data Tables
        3. 11.1.3. Product Catalog Repositories
        4. 11.1.4. Product Services
          1. 11.1.4.1. Product Views
          2. 11.1.4.2. ProductCatalogService
        5. 11.1.5. Controllers
        6. 11.1.6. Product Catalog Views
        7. 11.1.7. Setting Up IoC
      2. 11.2. SUMMARY
    3. 12. Implementing the Shopping Basket
      1. 12.1. IMPLEMENTING THE BASKET
        1. 12.1.1. Basket Domain Model
        2. 12.1.2. Create the Basket Tables
        3. 12.1.3. NHibernate Mapping
        4. 12.1.4. Basket Service
        5. 12.1.5. Basket Controller and Basket Views
      2. 12.2. SUMMARY
    4. 13. Customer Membership
      1. 13.1. CUSTOMER MEMBERSHIP
        1. 13.1.1. Customer Model
        2. 13.1.2. Customer Data Tables
        3. 13.1.3. Customer NHibernate Mappings
        4. 13.1.4. Customer Service
        5. 13.1.5. Authentication Service
          1. 13.1.5.1. Local Authentication with ASP.NET Membership
          2. 13.1.5.2. Web-Based Authentication with Janrain
          3. 13.1.5.3. Authentication Cookie
        6. 13.1.6. Customer Controller
        7. 13.1.7. Account Controllers
        8. 13.1.8. Customer Membership Views
        9. 13.1.9. Authentication Views
      2. 13.2. SUMMARY
    5. 14. Ordering and Payment
      1. 14.1. CHECKOUT
        1. 14.1.1. Order Model
        2. 14.1.2. Order Data Tables
        3. 14.1.3. Order NHibernate Mappings
        4. 14.1.4. Order Service
        5. 14.1.5. Taking Payment with PayPal
        6. 14.1.6. Order, Payment, and Checkout Controllers
        7. 14.1.7. Order and Checkout Views
      2. 14.2. SUMMARY