joi, 20 mai 2010

Supervising Pattern and Presentation Pattern

Supervising Pattern and Presentation Pattern


There are specialization of Model-View-Presenter
In this model there are 3 components involved:
  • UI
    • it is around the notion of View
    • sometimes it contains login in the view's code-behind file.
    • in WPF case, the pure UI: the view may be declaratively defined in XAML as a data template or control with no code-behind
  • Presentation
    • the application logic that is concerned with the application's use cases (or user stories) and that defines the logical behavior and structure of the application and that is independent of any specific user interface implementation
    • no direct reference to any UI control
  • Business Logic
    • any application logic that is concerned with the retrieval and management of application data and for making sure that any business rules that ensure data consistency and validity are imposed
    • should not contain any behavior or application logic that is specific to a use case or user story

Use to maximize testability.

Supervising Pattern

  • It is known,and, as the Supervising Controller pattern
  • The view class:
    • uses data binding to retrieve and update data directly from the model.
    • manages the controls on the user interface and forwards user events to a presenter class. 
    • manages the user interface controls and encapsulates any visual state or behavior that is specific to the UI
    • the view is updated through presenter and data binding
    • it is like of an observer of the model
  • The presenter 
    • coordinates any additional interaction between the view and the model that cannot be achieved through simple data binding
    • encapsulates presentation logic that interprets user gestures into actions against the model
    • communicates with the View through a interface (good for testability)
    • contains the logic to respond to the events, update the model 
  • Model
    • To support data binding, the model should implement the INotifyPropertyChanged interface.
    • Any objects provided to the view through properties should similarly support the INotifyPropertyChanged or INotifyCollectionChanged interfaces

Presentation Pattern

  • Provides a façade over the model and coordinates all of the view's interaction with it
  • The data that you want to display requires some form of conversion or adaptation before it can be displayed in the user interface.
  • The data that you want to display requires some form of validation before it can be updated by the user interface. 
  • The view acts as an observer of the Presentation Model, and the Presentation Model acts as an observer of the Model
  • The presentation model
    • should be designed to provide a public interface that can be easily consumed by a view
    • should be designed to support data binding, commands, and data templates.
      • Data Binding:
        • Presentation can be bound to app data
      • Commands
        • allow the user interface to interact with the application's functionality in a declarative and automatic way without requiring any complex event handling code in the view's code-behind file.
        • can be invoked as the user interacts with the UI, and the UI can be automatically updated as the underlying command becomes enabled or disabled.
        • WPF controls can be easily associated with a command through the Command property
        • The Composite Application Library provides the DelegateCommand and CompositeCommand classes to make this easy to do
      • A data template declares user interface controls that will be data bound at run time to the underlying object.

       <TextBlock Text="{Binding Path=TaskName}" /> 
<TextBlock Text="{Binding Path=Description}"/>
<TextBlock Text="{Binding Path=Priority}"/>

Model-View-View Model

WPF View: 
- should be as much as possible only XAML. 

View Model:
  • it is the DataContext for the WPF View
  • it will contain the logic
  • exposes public properties that WPF view will bind to
    • Dependency properties: for individual property like text, enable
    • ObservableCollection: for controls like ListBoxes, GridViews

- the source of data


Composite Application Guidance for WPF and Silverlight - October 2009

Niciun comentariu:

Trimiteți un comentariu