Semi-sophisticated MVPs

I am working on a .NET 3.5 application with slightly complicated behavior. This is for book inventory. To give you an idea, the workflow will be as follows:

  • User enters ISBN code
  • If the ISBN is valid, check if it exists,
  • If it is valid and exists, show information about the book and enable the save button, if not, click the "add book" button
  • If this is not valid, show the error
  • In the end, the user clicks โ€œsaveโ€, so the entry must be saved.

These are four responsibilities:

  • Verify ISBN,
  • Check the existence of the book,
  • Show book info,
  • Save the new data about the book.

My question is: should I store the application logic in one MVP structure or should I divide it into four MVP structures, one for each responsibility?

Saving in one MVP structure will be

  • make the model more complex
  • make test setup more complicated (there is a lot of setup code for each test to select the correct validator, returned book, etc., even if they are not used),
  • make presentation logic easier to follow

Saving in separate MVP structures will

  • simplify the model
  • create simpler tests for each lead,
  • difficulty in interactions between the presenters (how can I signal to the presenter that the ISBN is valid so that the book data can be indicated?)

I try the first principles of Presenter, so: - Keep the presentation mute (therefore there are no events like "Presenter one validated the ISBN"), - Keep speakers stateless, - Keep models simple (enough)

Anyone have an idea on how best to do this?

+4
source share
1 answer

I would go with one presenter, but delegated validation, etc. ISBN numbers per service.

Something along these lines in the presenter for entering ISBN:

public void IsbnEntered() { var isbn = view.Isbn; if (isbnService.NumberIsValid(isbn)) { var details = isbnService.RetrieveDetailsForIsbn(isbn); if (details != null) { view.Display(details); view.EnableSaveButton(); } else { view.DisplayError("ISBN could not be found"); } } else { view.DisplayError("Invalid ISBN"); } } 

Here the responsibilities are clearly defined. IsbnService is responsible for processing the ISBN, a presentation for displaying and entering data, and the host controls the interaction between them.

+1
source

All Articles