Download presentation
Presentation is loading. Please wait.
1
CO6025 Advanced Programming
Week 2 Introduction to MVC
2
Introduction We will use ASP.NET MVC 2.0 Primary language C#
Range of software technologies – AJAX, SQL Server, Entity Framework, LINQ, Interfaces, Generics Supporting textbook – Professional ASP.NET MVC 2.0 by Galloway, Hanselman, Haack, Guthrie and Conery, ISBN: You must download the free Chapter 1 – Nerd Dinner from
3
Design patterns Software development in the past focussed on coding and algorithms Methodologies direct the development effort A design pattern is a tried and tested way of solving a particular problem using a range of techniques. Patterns are not usually language or environment specific Patterns allow developers to build applications without having to re-invent the wheel. Convention over configuration – if everyone does it, then build it into the development environment. The DRY principle – Don’t Repeat Yourself.
4
Why MVC? Separation of concerns Not just easy to test -
Enables Test Driven Development (TDD) When used with other design patterns promotes code re-use (DRY) at several levels ASP.NET MVC allows for: Clean XHTML Search engine friendly URLs Integration with AJAX (jQuery and MS) Use of a variety of DB technologies
5
MVC Model View Controller
The part of the system which concerns itself with the data, how you access it and the business rules for working with it. View The applications user interface Controller The part of the system which coordinates user interactions, and handles the ‘flow’ of the application
6
MVC interactions Model Controller View
7
The Model There is no direct interaction with the view(s).
The model contains Classes for interacting with the data (Database, XML, whatever!) Validation logic Code to manipulate data Structured access to data to enforce the business logic of the system Usually wrapped up using a rigorous ‘interface’. The interface exposes a minimum surface area for the application to access and work with data.
8
The View(s) A View is a single element of the user interface (i.e. a web page). The view may display some aspect of the model (e.g. a list of products) It may allow the user to enter/alter data. The view communicates directly with the controller to signal the user interaction: E.g. click a submit button following an edit E.g. link to another view
9
The Controller(s) A controller acts as the coordinator between the model and the view(s). A user interaction is handled by the controller: It may be to retrieve structured data from the model and return it to another view It may be to pass data into the model and handle any validation issues before returning to another view (error page or confirmation etc.)
10
ASP.NET MVC 2.0 Current release of MVC
Built into the .NET framework v4.0 with VS 2010 Version 3.0 is available for preview. You create an ASP.NET MVC 2.0 project (not website – though it is a Web project) The default project contains a dummy application with all required basic elements (except model is minimal) Will also produce a test project with a set of basic tests
11
Demonstration Download the basic projects from this week’s eLearning page Quick look at the default MVC project. Stripping the default to it’s minimal implementation – the ‘clean’ starting point. Simple intro to database data handling
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.