Saturday, October 1, 2011

Presentation Tier:

Presentation Tier contains graphical display components and files such as ASPX, ASCX, Master pages, Style Sheets, and so on. Usually “Presentation Tier” is a web site or web application. All ASPX or ASCX pages contain HTML design where we add asp.net controls like buttons, textboxes, data controls, validation controls and so on. And all these aspx/ascx pages contain code behind files where we write the page specific code like filling drop downs, binding data controls, validating input data etc.

Now start creating class for this . Here we have two ways. Either we can access the business layer directly by calling the object. another option is clearly separate these  two layers using the design pattern. Lets follow the second method, which is comparatively newer and more professional way of approaching. So Our next requirement is to separate entire business logic from UI.Here we need some design patterns to be implemented . Here i am trying to follow one which is called MVP (Model View Presenter). This is introduced in layer and UI. So, UI cannot access business layer directly, all calls to business layer is routed through a view.



The first step is to create a aspx page. This would be the view part of our web application. Now create a library for presenter. We are going to add a class ie , the presenter for already added view part  . Before doing this i would like to call your attention into one more design pattern. You can avoid this. But using this also would be a nice practice.It is called "Abstract Factory". You cant  use the objects of the classes directly. Instead of that you will have to use something called "Abstract Products" . Its not that complicated. Create the library for the presenter interface first, then add presenterinterface into this.  Now in view , create objects of presenterinterface and initialize using presenterclass. This is called abstract products. Now we achieved two things. First Our business logic is going to be fully separated from your UI. The second , code in business will be added only at run time . It gives amazing flexibility to change your business without changing anything in your view.


Ok, we now just finished our two layers. We created the view where your code behind is located. Then we made interface for presenter to achieve abstract factory design pattern. Now we are calling the abstract product to connect to the business class.Calling business class from the presenter is included in the next topic, ie Business tier. Please check the following code for the first two layers.


 View and presenter


 An ASP.Net web site  contains ASPX, ASCX, Master Pages, Style sheets, Images and Resource files etc. All ASPX and ASCX files are divided into two separate files called as HTML designer and Code behind files. HTML designer has all the ASP.Net web controls. On other hand code behind files are used to write page specific code. All these code behind classes are derived from System.Web.UI.Page and Interfaces defined in Views library where all views (Views in MVP pattern) have been defined.

The first step is to create a view library, create the library and add the following code


---------------------------------------------------------------------------------
namespace Views
{

public interface IBluePrintView 
{
// Define everything required for your  code behind class here

}
}

---------------------------------------------------------------------------------
Now create Code behind class which is  in CS file by inheriting the view.


---------------------------------------------------------------------------------
 
namespace IViews
{

public partial class BluePrint : IBluePrintView

{

//Your internal variables here
BluePrintPresenter localPresenter;

#region OnInit
    /// <summary>
    /// Overriden method OnInit.
    /// </summary>
    /// <param name="e">EventArgs object.</param>
    protected override void OnInit(EventArgs e)
    {
        BlueprintPresenter bluePresenter = new BlueprintPresenter(this);
        bluePresenter.GetPresenterVal();


    }
    #endregion OnInit

}


---------------------------------------------------------------------------------

 Now add presenter library


---------------------------------------------------------------------------------
Namespace presenter

{
public class BluePrintPresenter

{

IBluePrintManager blueManager = new BluePrintManager();

public void GetPresenterVal()
        {

BluePrintInfo blueInfo = blueManager.GetManagerVal();

         }


}
}


---------------------------------------------------------------------------------

Please go to Business Tier to know what is IBluePrintManager and the business .

 






 














1 comment: