Thursday, June 14, 2012

UI Design Patterns


Option 1: (without testability)
MVP
Application Controller
  1. Each form has its own controller
  2. Controller interact with its form via its public interface (property, event, methods)
  3. For forms, other than the public interface (property, event, methods), everything else is private. (not accessible by its own controller)
  4. User Controls do not have its own controller. Hosting form interact with its user controls via  public interface of the controls (property, event, methods)
  5. User controls is private to hosting form, the controller of the form does not have the knowledge of the user controls it hosts.
  6. Forms has no knowledge of their respective controller
  7. For each business process (each transaction), there is a Business Process Controller.  BPC complete its process by interact with public interface of Controllers.
Benefits
  1. “Separation of Concerns” leads to cleaner code and easy to maintain.
  2. Reusability on User Controls
  3. Reusability on forms / controllers
Option 2 (with testability)
  1. Each form has its own Presenter. Each form implement a specific interface (e.g IMyForm and MyForm)
  2. Presenter interact with its form via the interface the form is implemented
  3. For forms, other than the implementation of the interface, everything else is private. (not accessible by its own controller)
  4. User Controls do not have its own Presenter. Hosting form (or control)  interact with its user controls via  public interface of the controls (property, event, methods)
  5. User controls is private to hosting form, the Presenter of the form does not have the knowledge of the user controls it hosts.
  6. Forms has no knowledge of their respective Presenter
  7. Each Presenter implement a specific interface IPresenter
  8. For each business process (each transaction), there is a Business Process Controller.  BPC complete its process by interact with the interface of the Presenters.
Benefits
  1. Separation of Concerns, cleaner code, easy to maintain
  2. Reusability of user controls
  3. Reusability of Presenters / forms
  4. Testability on Presenters
  5. Testability on Business Process Controller
Option 3 (with testability on user control logic)
  1. With everything described in option 2
  2. Make a presenter for each user control,
  3. Make user control implement its own interface (MyControl implements IMyControl)
  4. My the presenter of the user control interact with user controls via its interface
Additional benefits:
        The user process logic for user controls is also unit testable.

No comments:

Post a Comment