MVC Questions

Source MSDN
1
MVC is a standard design pattern that many developers are familiar with. The Model-View-Controller
(MVC) architectural pattern separates an application into three main components: the model, the view,
and the controller. The ASP.NET MVC framework provides an alternative to the ASP.NET Web Forms
pattern for creating Web applications. The MVC pattern helps you create applications that separate the
 different aspects of the application (input logic, business logic, and UI logic), while providing a loose
coupling between these elements. The pattern specifies where each kind of logic should be located in
 the application. The UI logic belongs in the view. Input logic belongs in the controller. Business logic
 belongs in the model. This separation helps you manage complexity when you build an application,
because it enables you to focus on one aspect of the implementation at a time. For example, you can
 focus on the view without depending on the business logic.
The loose coupling between the three main components of an MVC application also promotes parallel
development. For example, one developer can work on the view, a second developer can work on the
controller logic, and a third developer can focus on the business logic in the model.

2
 In which assembly is MVC framework defined?
System.Web.Mvc

3
The MVC framework includes the following components:
Models. Model objects are the parts of the application that implement the logic for the application's data
 domain. Often, model objects retrieve and store model state in a database. For example, a Product
object might retrieve information from a database, operate on it, and then write updated information
back to a Products table in a SQL Server database.
In small applications, the model is often a conceptual separation instead of a physical one. For example,
 if the application only reads a dataset and sends it to the view, the application does not have a physical
 model layer and associated classes. In that case, the dataset takes on the role of a model object.Views.
Views are the components that display the application's user interface (UI). Typically, this UI is created
from the model data. An example would be an edit view of a Products table that displays text boxes,
 drop-down lists, and check boxes based on the current state of a Product object.Controllers. Controllers
are the components that handle user interaction, work with the model, and ultimately select a view to
render that displays UI. In an MVC application, the view only displays information; the controller handles
 and responds to user input and interaction. For example, the controller handles query-string values,
and passes these values to the model, which in turn might use these values to query the database.

4
MVC pattern makes it easier to test applications than it is to test a Web Forms-based ASP.NET Web
application. For example, in a Web Forms-based ASP.NET Web application, a single class is used both to
display output and to respond to user input. Writing automated tests for Web Forms-based ASP.NET
 applications can be complex, because to test an individual page, you must instantiate the page class,
all its child controls, and additional dependent classes in the application. Because so many classes are
 instantiated to run the page, it can be hard to write tests that focus exclusively on individual parts of
the application. Tests for Web Forms-based ASP.NET applications can therefore be more difficult to
implement than tests in an MVC application. Moreover, tests in a Web Forms-based ASP.NET application
 require a Web server. The MVC framework decouples the components and makes heavy use of
interfaces, which makes it possible to test individual components in isolation from the rest of the
 framework.

5 Advantages of MVC based applications?
The ASP.NET MVC framework offers the following advantages:
•It makes it easier to manage complexity by dividing an application into the model, the view, and the
 controller.
•It does not use view state or server-based forms. This makes the MVC framework ideal for developers
who want full control over the behavior of an application.
•It uses a Front Controller pattern that processes Web application requests through a single controller.
This enables you to design an application that supports a rich routing infrastructure. For more
information, see Front Controller on the MSDN Web site.
•It provides better support for test-driven development (TDD).
•It works well for Web applications that are supported by large teams of developers and Web designers
who need a high degree of control over the application behavior.

6 Advantages of web-based applications?
The Web Forms-based framework offers the following advantages:
•It supports an event model that preserves state over HTTP, which benefits line-of-business Web
application development. The Web Forms-based application provides dozens of events that are
 supported in hundreds of server controls.
•It uses a Page Controller pattern that adds functionality to individual pages. For more information,
 see Page Controller on the MSDN Web site.
•It uses view state or server-based forms, which can make managing state information easier.
•It works well for small teams of Web developers and designers who want to take advantage of the
large number of components available for rapid application development.
•In general, it is less complex for application development, because the components (the Page class,
controls, and so on) are tightly integrated and usually require less code than the MVC model. 

7
 Basic Features of MVC framework?
The ASP.NET MVC framework provides the following features:Separation of application tasks (input
logic, business logic, and UI logic), testability, and test-driven development (TDD). All core contracts in
 the MVC framework are interface-based and can be tested by using mock objects, which are simulated
 objects that imitate the behavior of actual objects in the application. You can unit-test the application
without having to run the controllers in an ASP.NET process, which makes unit testing fast and flexible.
You can use any unit-testing framework that is compatible with the .NET Framework.An extensible
and pluggable framework. The components of the ASP.NET MVC framework are designed so that they
 can be easily replaced or customized. You can plug in your own view engine, URL routing policy,
action-method parameter serialization, and other components. The ASP.NET MVC framework also
supports the use of Dependency Injection (DI) and Inversion of Control (IOC) container models. DI
 enables you to inject objects into a class, instead of relying on the class to create the object itself.
 IOC specifies that if an object requires another object, the first objects should get the second object
from an outside source such as a configuration file. This makes testing easier.Extensive support for
 ASP.NET routing, which is a powerful URL-mapping component that lets you build applications that
have comprehensible and searchable URLs. URLs do not have to include file-name extensions, and are
 designed to support URL naming patterns that work well for search engine optimization (SEO) and
representational state transfer (REST) addressing.Support for using the markup in existing ASP.NET
 page (.aspx files), user control (.ascx files), and master page (.master files) markup files as view
templates. You can use existing ASP.NET features with the ASP.NET MVC framework, such as nested
master pages, in-line expressions (<%= %>), declarative server controls, templates, data-binding,
 localization, and so on.Support for existing ASP.NET features. ASP.NET MVC lets you use features
 such as forms authentication and Windows authentication, URL authorization, membership and roles,
 output and data caching, session and profile state management, health monitoring, the configuration
system, and the provider architecture.

8
 What is REST model?
Representational State Transfer, or REST for short?
Well, REST is an architectural pattern that defines how network resources should be defined and
addressed in order to gain shorter response times, clear separation of concerns between the front-end
and back-end of a networked system. REST is based on three following principles:
•An application expresses its state and implements its functionality by acting on logical resources
•Each resource is addressed using a specific URL syntax
•All addressable resources feature a contracted set of operations
       
9
 Difference between ASP.NET and MVC?
It is an ASP.NET framework that performs data exchange by using a REST model versus the postback
 model of classic ASP.NET. Each page is split into two distinct components -controller and view – that
 operate over the same model of data. This is opposed to the classic code-behind model where no
 barrier is set that forces you to think in terms of separation of concerns and controllers and views.
However, by keeping the code-behind class as thin as possible, and designing the business layer
 appropriately, a good developer could achieve separation of concerns even without adopting MVC
 and its overhead. MVC, however, is a model superior to a properly-done code-behind for its inherent
 support for test-driven development. 

10
 MVC for ASP.NET programmers?
What can be the quickest and most effective way to explain the MVC Framework to ASP.NET
 developers. It's like having a central HTTP handler that captures all requests to resources identified
with a new extension. This HTTP handler analyzes the syntax of the URL and maps it to a special server
 component known as the controller. The controller supports a number of predefined actions. The
 requested action is somehow codified in the URL according to an application-specific syntax. The
central HTTP handler invokes the action on the controller and the controller will process the request
up to generating the response in whatever response format you need. The response is generated
through a view component.
What here I called the "central HTTP handler" plays the same role that was of the System.Web.UI.Page
 class in classic ASP.NET. The Page is the handler responsible for any .aspx request and generates the
 markup using the code-behind class and serves it back using postbacks. In the MVC Framework, this
 pattern - hard-coded in the ASP.NET runtime and not subject to change until the whole ASP.NET
platform is rewritten - is simply implemented using an alternative HTTP handler and an alternative
model based on REST and MVC. 

11
 When to use MVC?
I would say one very compelling scenario to use MVC is if you have a group of experienced .NET
developers who dont have experience with WebForms. They don't need to go into details and
complexity of abstraction and postbacks to use MVC.
      









1 comment:

  1. This is an exception, Got some high level interview questions and answers. Thanks

    ReplyDelete