Continuation of MVPC – Implementation

Last time I talked about Nette in MVPC context. It was a good framework for websites, but it didn't work very well if the access point to your application was a CLI or an API. This time I will show you how to solve this issue and how to integrate Nette into MVPC designed application.

PV vs. MC

In The difference between presenter and controller article I have shown you 3 different presenters all collaborating with only one controller. Each of these presenter has to use its own view, since they are displaying completely different outputs. On the other hand there was need for only one model, since it's only the shared controller that is collaborating with the model. This brings up a pattern, where there are several presenter-view(PV) pairs for only one model-controller(MC) pair. This pattern can be illustrated as:

Here for any request to the application the following logic applies:

  1. Based on the type of request (the application enpoint) an appropriate Bounded context is selected
  2. Base on the coller of the request (CLI, website, API) the appropriate Presenter is selected
  3. The presenter then calls the shared controller
  4. The controller performs the desired action and optionally uses the model layer
  5. The presenter after recieving the response from the controller prepares a view
  6. The presenter sends the view as a response

The diagram therefore suggest to develop the interface public interface of controller first. Then you can simultaneously develop each PV pair independently from the other PV pairs while you can also be developing your MC pair. This hign level of decoupling allows several developers to work on the bounded context at once.

PV and Nette

This level of decoupling also allows to use Nette for what is its strength. If we look where Nette fits in the diagram, it is a perfect example of PV framework.

This statement is further supported by the fact that Nette didnt have a model layer by default for a long time and that is heavily build around services (more on this in the next article). With this design, Nette does not have to care about model, it is completely isoled from ani API or CLI calls. It only serves the website.

Other PV

You could use Nette(or any other website framework) for the website, but what about the other two cases? Well this is the beauty of this design. It does not matter. It doesn't even have to be the same language. You could use restify nodeJS module for your REST API and resty wapper for cURL for your CLI. But with using different languages for your presenters brings problem in collaboration with your controller. What the problem is, how to solve it and the finalization of MVPC design will be in the next article.

Continues by MVPC – Introducing mSPV