Wednesday, 29 January 2014

MVP Pattern and Frameworks

 

 

The MVP pattern is an Architecture Pattern used to build ASP.net applications.  It refers to splitting up the responsibilities for gathering, displaying, and storing data from a web page into separate objects: a Model object, a View object, and a Presenter object.  The View is often an interface which is then implemented by an ASP.net web page; the Model is a business object.  The Presenter negotiates the transfer of data between the other two objects.  The MVP pattern descends from the Model View Controller pattern that was originally described in Smalltalk.

Since, Nevertheless there are two major drawbacks in the traditional MVC approach.

 

image

 

  • First is a higher complexity because of the observer mechanism: in order to update the view the controller must make changes to the presentation model, which will trigger the view update. Such indirect relationship may be difficult to understand. Instead the controller could simply send a message to the view, however such direct linking is not allowed in MVC.
  • The other shortcoming is that MVC does not conform to the modern UI programming environments where widgets themselves handle user gestures. For example form classes (either Web or Windows) in .NET applications by default contain handlers for user input. Thus it would be difficult to break the common paradigm and make controllers receive the user input instead of views.

 

Firstly according to MVP, direct requests from the controller to the view become possible. Thus the controller itself may trigger the view updates instead of performing a round trip through the presentation model. In this sense the controller in MVP contains the presentation model from MVC. That is probably the reason why the controller in MVP is referred to as presenter

 

 

image

 

 

 

 

image

 

 

Here we must note that although the controller has a link to the view object it does not depend on the concrete view class. Instead the controller treats the view in an abstracted way by the means of a separated interface implemented by the view (see the figure above). For example, the encyclopedia controller will communicate the view via the IEncyclopediaView interface with chooseExplFrom(…) and displayExpl(…) operations. Since such separated interface is a part of the application logic, the dependency runs from the presentation to the application logic but not vice versa.

Next thing that makes MVP more convenient (in contrast to MVC) is that it allows views to receive user input. Such behavior fits well modern UI environments. For instance in Windows keyboard and mouse events are handled by UI controls and forms, in ASP.NET user requests are processed by Web page classes. Though the view in MVP receives the user input it should merely delegate all the processing to the controller.

The next figure demonstrates the interactions in MVP by the example of the encyclopedia application. As we can see direct calls from the controller to the view (via the IEncyclopediaView interface) make the overall picture less complicated than that in MVC. Yet the clear separation of responsibilities between the controller (application logic) and the view (presentation mechanism) still remains, in particular allowing the developer to easily support interchangeable views for Web and Windows environments.

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

Demo of WEB Form Example

image

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

image

 

image

 

 

 

Demo of Windows Form example

image

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

MVP Framework for .NET Application

 

Coming Soon…

 

 

 

 

 

 

 

 

Blogger Labels: Pattern,Frameworks,Architecture,data,Model,View,Presenter,interface,Controller,Smalltalk,drawbacks,observer,mechanism,presentation,relationship,Instead,message,environments,widgets,user,example,Windows,handlers,Thus,paradigm,controllers,Here,IEncyclopediaView,logic,dependency,vice,instance,events,Though,interactions,separation,developer,Framework,Application,Soon,encyclopedia

ADO.NET Fundamentals

 

 

ADO.NET Overview

 

image

 

 

 

image

 

 

 

 

image

 

 

 

 

 

Setting Up Your Environment

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

image

 

 

 

 

 

Connect to A Data Source Using ADO.NET

 

image

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

Setup and Connecting with WinForm

 

image

 

 

 

SqlConnectionStringBuilder

 

image

 

 

 

image

 

 

 

image

 

 

 

 

 

 

 

Retrieving Data from A Data Source

 

image

 

 

 

Build SQL Statement

 

image

 

 

 

 

Implement Data Layer

 

image

 

 

 

 

image

 

 

 

 

Design Winform Application

 

image

 

 

 

image

 

 

 

image

 

 

 

 

Store Procedure call via ADO.NET

 

image

 

 

 

image

 

 

 

 

 

Inserting, Deleting, Updating Data from A Data Source

 

image_thumb[90]

 

 

 

 

 

Prepare Execute Non Query

 

image_thumb[93]

 

 

 

 

Creating Stored Procedure

 

image_thumb[95]

 

 

 

 

image_thumb[97]

 

 

 

 

 

Inserts With Execute Scalar

 

image_thumb[101]

 

 

 

image_thumb[99]

 

 

 

image_thumb[104]

 

 

 

 

Using Output parameter

 

image_thumb[106]

 

 

 

image_thumb[108]

 

 

 

image_thumb[110]

 

 

 

 

 

Using Return Value parameter

 

image_thumb[112]

 

 

image_thumb[115]

 

 

 

image_thumb[117]

 

 

 

 

 

Delete information from DB via Execute Non Query

 

image_thumb[119]

 

 

 

 

image_thumb[121]

 

 

 

image_thumb[123]

 

 

 

 

image_thumb[125]

 

 

 

 

Updates with Execute Non Query

 

image_thumb[127]

 

 

 

 

image_thumb[129]

 

 

 

 

image_thumb[131]

 

 

 

image_thumb[133]

 

 

 

 

Understanding Errors with ADO.NET

 

image_thumb[135]

 

 

 

image_thumb[138]

 

 

 

image_thumb[140]

 

 

 

 

 

image_thumb[142]

 

 

 

 

image_thumb[145]

 

 

 

 

image_thumb[147]

 

 

 

 

Catch SQL Exception Errors

 

image

 

 

 

image

 

Note:  Change the Date source which does not exist.

 

 

 

 

image

 

 

 

 

Use Raise Error

 

image

 

 

 

image

 

 

 

image

 

 

 

 

Using SQL Data Adapter

 

image

 

 

 

 

image

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

Load A Data Table via SQL Adapter

 

image

 

 

 

 

Bind the Data Table

 

 

image

 

 

image

 

 

 

image

 

 

 

 

Update with SQL Adapter

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

 

Client Side Performance Tracking

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

Setup Client Statistics

image

 

 

 

 

image

 

 

 

 

Retrieve Statistics

 

image

 

 

 

 

 

Display All statistics

 

image

 

 

 

 

image

 

 

 

image

 

 

image

 

 

 

 

Round Trips

 

image

 

 

 

image

 

 

 

 

 

Managing Concurrency and Transactions

 

image

 

 

 

 

image

 

 

 

 

image

 

image

 

 

 

 

 

 

image

 

 

 

 

 

Concurrency checkings with WHERE Clause

 

image

 

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

Concurrency checking with SQL Adapter

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

 

 

Concurrency checking with Time Stamp

 

image

 

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

 

 

 

SQL Transaction

 

image

 

 

 

image

 

 

 

 

 

Transaction Scope

 

image

 

 

 

 

image

 

 

Note: If you make different DB server calls in this transaction scope that is called as DTC.

 

 

 

Server Transaction

 

image

 

 

 

 

 

Connection Pooling

 

image

 

 

 

image

image

 

 

 

 

image

 

 

 

 

image

 

image

 

 

 

 

 

image

 

 

 

 

SQL Server Profiler and Pooling

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

 

 

Performance Monitor and Pooling

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

image

 

 

 

 

 

Using XML with ADO.NET

 

image

 

 

 

 

image

 

 

 

 

Writing XML into DB

 

image

 

 

 

image

 

 

 

image

 

 

 

 

 

Reading XML from DB

 

image

 

 

 

image

 

 

 

image

 

 

 

 

image

 

 

 

 

image

 

 

 

image

 

 

Blogger Labels: Fundamentals,Overview,Environment,Connect,Data,Source,Setup,WinForm,SqlConnectionStringBuilder,Build,Statement,Implement,Layer,Design,Application,Procedure,Prepare,Execute,Query,Inserts,Scalar,Output,parameter,Return,Value,Delete,information,Updates,Errors,Catch,Exception,Note,Change,Date,Raise,Error,Adapter,Load,Table,Bind,Update,Client,Side,Performance,Statistics,Retrieve,Display,Round,Trips,Concurrency,Transactions,WHERE,Clause,Time,Stamp,Transaction,Scope,server,Connection,Profiler,Monitor