ASP.NET MVC: Views
Download
Report
Transcript ASP.NET MVC: Views
Todd Snyder
Development Team Lead
Infragistics Experience Design Group
ASP.NET MVC:
PATTERNS & PRINCIPALS
ASP.NET MVC – Patterns & Principals
Concepts and Patterns
MVC/MVP Frameworks
Best Practices
ASP.NET MVC – Patterns & Principals
Concepts and Patterns
What is a pattern?
BaseSalesTax
NJSalesTax
NYSalesTax
PASalesTax
A reusable solution to a commonly occurring problem within a specific
context. They are blue prints for solving a problem and not a finished
solution. Depending on the platform and environment you are working
with the implementation of a pattern may be different.
Design Principals - Drive Design
Separation of Concerns
Loosely Coupled/High Cohesion
Flexibility/Adaptable
Code Reuse
Testability
How many data access technologies do we need?
MVC Pattern – Separating Concerns
Behaviors (Business Rules) and Data
Real world domain classes (Customers, Orders, Products)
Model
Handles Input Requests
Interacts with Model
Determines which view to render
Controller
View
Renders the contents of a model
Maintains consistency between itself & the model (Stateful)
One Pattern – Many Implementations
Supervising Controller
Model
Passive View
Model
Presenter
(Controller)
View
Presenter
(Controller)
View
Presenter/View Model
Presenter
Model
View
Model
Presenter
(Controller)
MVC (Controller) vs MVP (Presenter)
MVC Pattern
Controller Drives Flow (Front Controller)
Based on UI Action (Behaviors)
Can Determine which view to display
View usually has direct access to the model
MVP Pattern
View Drives Flow & Delegates to the presenter
View & Model more loosely coupled
Traditionally Easier to unit test (Using Interface)
View to presenter usually map one to one
Dependency Injection (IOC)
Concrete Dependency
Interface (Abstraction)
Dependency
Product
Controller
Product
Controller
Check Out
Service
IService
Check Out
Service
Injected Dependency
Product
Controller
Assembler
IService
Check Out
Service
ASP.NET MVC – Patterns & Principals
MVC/MVP Frameworks
Frameworks
Windows
Composite Application Block (CAB)
Smart Client Software Factory (SCSF)
Prism (CAB for WPF)
Web
Web Client Software Factory (WCSF)
ASP.Net Model View Controller Framework
MonoRail – Open Source MVC Framework
JAVA
Struts
Spring (Ported to .Net)
ASP.NET MVC vs Web Form
ASP.Net Web Form
(Page Controller)
View (ASPX)
Code Behind
(Controller)
Data
Model
ASP.Net MVC
(Front Controller)
List View
Product
Controller
Model
Detail View
Data
ASP.NET MVC – In Action (Basic)
List View
(HTML)
Product
Controller
Model
Data
Detail View
(HTML)
View Result
ASP.NET MVC – In Action (AJAX)
Complex
View(HTML)
Product
Controller
Model
Data
Content
JSON Result
ASP.NET MVC – Patterns & Principals
Best Practices
Patterns, Patterns, Pattern …
Creational Factory, Singleton, Builder
Structural
Adapter, Decorator, Facade, Proxy
Behavioral Command, Observer, Strategy,
Template Method, Visitor
Domain
Transaction Script, Domain Model,
Table Module, Service Layer
Data
Data Gateway, Active Record,
Data Mapper, Repository
Domain Model – (The Heart of the System)
Repository Pattern
Data
Model
Repository
XML
Cache
Mapper(s)
Service Layer Pattern
Product
Controller
Business API
Service
yer
Model
Layer
Persist Ignorance
Repository
TDD & Refactoring
Test Driven Development
Focuses on design and code quality
Tests drive class design (Iterative
approach)
Not a replacement for functionality
testing
Use Mocking to test classes in isolation
Refactoring
Process of improving the design of
existing code
Focus on making small changes
Tests help drive the process
Code Smells
Source: http://www.agileprogrammer.com/uploads/bradwils/red_2Dgreen_2Drefactor.png
Q&A
(thanks!)
Todd Snyder
Email: [email protected]
Blog: http://blogs.infragistics.com/blogs/tsnyder
Resources
Todd Snyder
[email protected]
http://blogs.infragistics.com/blogs/tsnyder
Books
Agile Principles, Patterns, and Practices in C#
Patterns of Enterprise Application Architecture
Refactoring to Patterns
Refactoring: Improving the design of existing code
Domain-Driven Design: Tackling Complexity in the Heart of
Software
Web Sites
Enterprise Patterns defined by Martin Fowler
GOF Patterns in C#
Object Oriented Analysis and Design
MVP Pattern in C#
Value of using the MVP Pattern