Thursday, November 17, 2011

MVP Pattern


MVP pattern is one of the major patterns used for extracting business logic outside of UI elements and by that, enabling unit testing the UI without the need for using specific UI based testing tools.
As technologies such as ASP.NET and Windows® Forms become more and more powerful, it's common practice to let the UI layer do more than it should. Without a clear separation of responsibilities, the UI layer can often become a catch-all for logic that really belongs in other layers of the application. One design pattern, the Model View Presenter (MVP) pattern, is especially well suited to solving this problem.

For follow MVP pattern, we divide whole solution in 3 different project as per bellow.
MVP Structure
  • Model Project (Class Library) :
    • DAL Classes (Data Access Layer):
      • Exchange data between your business objects, the DAL and vice versa. 
      • All interaction between your business objects and the DAL occurs by calling data access methods in the DAL from code in your business objects.
      • The method parameters and return values in the DAL are all database independent to ensure your business objects are not bound to a particular database.
    • BAL(Business Access Layer) Classes:
      • BAL contains business logic, validations or calculations related with the data.
      • Responsibility is to validate the business rules of the component and communicating with the Data Access Layer. 
      • Business Logic Layer is the class in which we write functions that get data from Presentation Layer and send that data to database through Data Access Layer.
  • Presenter Project (Class Library):
    • Presenter Class:
      • Orchestrates the overall interaction of the other components within the application.
      • Roles include the creation of the appropriate Models, Selections, Commands, Views, and Iterators, and directing the workflow within the application.
    • View Interface:
      • Interface class use for bridge between presenter class and View.
      • Define all properties and method related to UI(User Interface).
  • View Interface:
    • View project may be possible asp.net website, Silverlight application, WPF application or windows form application.
    • View contains only User interface of application. It contains user controls and forms for application. The View is the visual representation of the Model and is comprised of the screens and widgets used within an application.
    • Integrators are components which address how user events are mapped onto operations performed on the Model, such as mouse movements, keyboard input, and the selection of checkboxes or menu items.

No comments:

Post a Comment