Session State with MVP and Application Controller patterns - mvp

I've created an MVP (passive view) framework for development and decided to go for an Application Controller pattern to manage the navigation between views. This is targeted at WinForms, ASP.NET and WPF interfaces.
Although I'm not 100% convinced that these view technologies really swappable, that's my aim at the moment so my MVP framework is quite lightweight.
What I'm struggling to fit in is the concept of a "Business Conversation" that needs state information to be either (a) maintained for the lifetime of the View or, more likely, (b) maintained across several views for the lifetime of a use case (business conversation). I want state management to be part of the framework as I don't want developers to worry about it. All they need to do is to "start" a conversation, "Register" objects and the framework does the rest until the "end" a conversation.
Has anybody got any thoughts (patterns) to how to fit this into MVP? I was thinking it may be part of the Application Controller responsibility (delegating to a Conversation Manager object) as it knows about current state in order to send the user to the next view.... but then I thought it may be up to the Presenter to start and end the conversation so then it comes down the presenters to manage conversations and the objects registered for the that conversation. Unfortunately that means presenters can't be used in different conversations... so that idea doesn't seem right.
As you can see, I don't think there is an easy answer (and I've looked for a while). So anybody else got any thoughts?

The classes needed to support a Business Conversation should reside in a presenter if it only involves the User Interface. Otherwise it should be in the Model and controller from the View to the Presenter to the Model. With information about Business Conversations flowing the other way. I suspect is something that can reside just in the Presenter.
Since all Views have access to the Presenter you then have the ability to structure the objects supporting the conversation so that they can be maintained across several views.
Remember Views are a window into what data resides in your software. They did little other display data and pass user interactions back into the presenter which does the logic.

Related

When does it make sense to use Actors in a web application

I have been browsing Typesafe Activator templates. Often in the Typesafe templates (Reactive Stocks / Maps / *) I see an actors folder within the app folder. Obviously, this is supposed to hold actors, but how would one add actors to a Play application. I know that Play is an MVC framework, and that means:
Models act as templates for structured data, and are used for interaction with the database and passed to views
Views are web pages, and typically can have data injected into them.
Controllers contain business logic, and may bridge models and views
If this is so, what are Actors for? What do they add that Models, Views, and Controllers do not provide? What would be some practical uses of Actors while developing reactive web applications?
EDIT
While reviewing Play documentation, I have found that Actors may be useful for scheduling. Are there any other uses for Actors?
The Play Framework uses controllers to handle the requests. The controller fetches the data from the models and transforms/filters/modifies it, so that the views can handle the data. The controller also contains the whole business logic.
The way the Play Framework is designed, those controllers should handle those requests either really quick, or return an asynchronous Promise. This is where the actors come in handy. If you have requests which take a long time to compute, you can use an actor to handle the request asynchronous. Have a look at the documentation.

purpose of adding events layer in DDD

I was going through with https://github.com/spring-guides/deprecate-tut-web tutorial on Spring. I am new to Spring . I have seen a few small Spring Web MVC tutorials before . Most other tutorials i have seen uses a service layer which is invoked from the web controller. But never have i seen the use of "events" layer as used in this tutorial. Is the layer really necessary, and if so what benefit does it give me ? I am also new to both DDD (Domain Driven Development) and TDD (Test Driven Development), some things just seem really redundant and over-complicated to me in this tutorial .. Can someone explain what is the purpose of this events layer and why should we use it ? Thank you in advance and sorry if it's a Noob question. :)
The purpose of domain events are notify any interested party that something has occurred in one of your domain objects. For example, if you hear a business expert say something such as "when an invoice is approved, release payment", then you probably want a domain event called InvoiceApproved. This way the payment related code can subscribe to that in the application layer and not be tightly coupled to the invoice logic and orchestration. Domain events are a very necessary and very powerful aspect of DDD.

Why Smalltalk-80 MVC cannnot be applied to web development?

I have read in some places that Smalltalk-80 original MVC is not applicable to web application development because (1) it was made to develop GUI components, not an entire application and (2) because model cannot communicate with view.
(1) is valid, but I do not understand (2). First, Smalltalk-80 MVC does not says that model communicates directly with view, it does so using events. Second, I have an assumption that only controller would be able to alter the model. Then, in a http request, controller layer alters model layer, which raise events which could be observed by view layer. The only diff to controller->model->controller->view (MVP - passive view) is how model notifies the view of its changes. Could someone clarify?

Why is MVC used on the server? Isn't it a client-side pattern?

I'm trying to learn web development.
I understand (mostly) the concept of MVC, but I'm confused about why an MVC model is used on the server side...like Spring MVC. Isn't the server side the Model and Services, and then the client side Services, View, and Controller (AngularJS even makes that pattern explicit on the client side)?
I'm really struggling with how the MVC model fits into or facilitates server-side development.
MVC is a pattern used by much more than just web applications. Any app with a UI could use an MVC pattern.
The idea is that you have a View (html, or a window in your OS, or even a report or something), and you have a model that represents the dynamic parts of that view. Then you have a controller that is dedicated to processing input and doing the "business logic" to generate the model and apply it to the view.
So.. for example on the Server you might have this MVC pattern:
A controller receives the HTTP request and processes it.
It builds a model
The model is applied to a view to generate HTML and send it back as a response.
On the client it will be similar (but a bit different in Angular's case):
A controller is used to determine and manipulate the model.
The model is then bound to your view via directives. (Angular is really more of an MVVM pattern, but it's similar enough)
The view is similarly bound to your model via directives. (this is where the MVVM part comes in).
The idea here is that both the model and the view are kept up to date by directives.
The controller just contains "business logic" for manipulating the model.
Clear as mud?
No worries. Just know this: It's just a common pattern. It's not "server specific" or "client specific". It can be used anywhere by anything requiring data to be scrubbed into templated output.
EDIT: More thoughts.
In the case of a Web API that serves up JSON (or even XML) on the server, you're still using MVC in most cases. This is because what you're doing is:
Process the request in a controller.
Build up the model in the controller.
Render the model to a "view", which in this case is a view that serializes it out as JSON.
In the good ol' days of yore, the client side was only a display. The server was responsible for communicating with the model, applying business logic, generating a view, and sending the static, rendered content back to the client (browser).
As the web matured, some of those responsibilities migrated from the server to the client. Now, the server-side is often a thin layer like RESTful API that stores the "official" business logic (rather than convenience logic on the client) and stores the model. But for performance and user experience, the client now stores a copy of the model in its own model layer, communicating with the server and/or local storage as necessary, and having its own controllers and view logic to provide an awesome user experience.
So does MVC still apply on the server? Yes! It's just different. The server often generates the initial view from which the client-side application runs (taking localization or internationalization into account, for instance) and still houses the official model. But more importantly, the "view" in MVC just changed. Instead of the server-side view being HTML, it's now JSON or XML that the client application consumes instead of just renders.
So for functionality's sake, we still use MVC on the server. But for an awesome user experience, we use MVC on the client-side now too.

What object handles switching views in a desktop MVC app?

In a desktop application that uses MVC, what object should be responsible for switching from one view to another? A controller at the next highest level of abstraction?
(Conceptual question not particular to language/platform.)
Yes, that would be correct. You can think of your controller as something of a traffic cop. It handles directing the incoming traffic through the appropriate channels (your business services), and then directs it to its next destination (the view).

Resources