generated from neutrons/python_project_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,4 @@ Contents | |
getting_started | ||
reference | ||
GUI_standards | ||
MVP_guidelines |