Skip to content

Commit

Permalink
mvp docs
Browse files Browse the repository at this point in the history
  • Loading branch information
searscr committed Mar 5, 2024
1 parent 12df72d commit 3d8a642
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
108 changes: 108 additions & 0 deletions docs/source/MVP_guidelines.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

.. _MVP_Guidelines:

==========================
Model-View-Presenter (MVP)
==========================

Overview
========

The Model-View-Presenter (MVP) pattern is a software design pattern
that separates the structure of an application into three main components:
Model, View, and Presenter. This separation enhances modularity, testability,
and maintainability of the codebase.

Components
===========

1. **Model:**
The Model represents the application's data and algorithm logic. It is
responsible for retrieving and manipulating data, as well as notifying the
Presenter of any changes. The Model is independent of both the View and the
Presenter.

2. **View:**
The View is responsible for presenting the data to the user and receiving
user input. It remains passive and delegates user interactions to the Presenter.
The View does not contain any application logic and is only concerned with
displaying information to the user. Each View is associated with a single Presenter.

3. **Presenter:**
The Presenter acts as an intermediary between the Model and the View. It
contains the application logic, responds to user input from the View, and
updates the Model accordingly. The Presenter also updates the View in response
to changes in the Model. This separation allows for easier testing and
maintenance of the application logic. There is only one Presenter for each View.

Communication Flow
===================

1. User interacts with the View by triggering events.
2. The View forwards user input events to the Presenter.
3. The Presenter processes the events, updates the Model as needed, and
communicates changes back to the View.
4. The View reflects the changes made by the Presenter.

.. graphviz::

digraph mvp_flow {
rankdir=LR;

// Nodes
node [shape=box];
User [label="User" shape=circle width=.15];
View [label="View"];
Presenter [label="Presenter"];
Model [label="Model"];

// User to View
User -> View [label="User Interaction" arrowhead="open"];

// View to Presenter
View -> Presenter [label="User Input Events"];

// Presenter to Model
Presenter -> Model [label="Update Model"];

// Model to Presenter
Model -> Presenter [label="Notify Changes"];

// Presenter to View
Presenter -> View [label="Update View"];

// View to User
View -> User [label="View Updates" arrowhead="open"];
}



Advantages
==========

1. **Separation of Responsibility:**
MVP separates the application into distinct components, promoting a clean and
modular code structure. This separation makes it easier to manage and test each
component independently.

2. **Testability:**
Since the application logic resides in the Presenter and Algorithms in the Model,
it is easier to unit test without involving the UI components. This facilitates
a more effective testing strategy.

3. **Maintainability:**
The clear separation of responsibilities makes the codebase more maintainable.
Changes in one component, such as the View or Model, do not directly impact the
others.

Usage
======

MVP is commonly used in GUI-based applications where a clear separation between
the user interface and business logic is crucial for maintainability and
testability.

.. note::

MVP is an evolution of the Model-View-Controller (MVC) pattern, addressing some of its limitations,
especially in terms of testing and code organization.
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
"sphinx.ext.coverage",
"sphinx.ext.graphviz",
]

autodoc_mock_imports = [
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ Contents
getting_started
reference
GUI_standards
MVP_guidelines

0 comments on commit 3d8a642

Please sign in to comment.