Point of presenter in clean architecture with MVC - clean-architecture

Reading the book clean architecture, I trying to figure out the best way to use the presenter in MVC. Since there is no code associated I'm having a hard time finding the need for a presenter.
It seems to me that the controller in MVC can be used for both controller and presenter. The usecase returns a model that you convert to a viewmodel in the controller.
If the presenter is to be used at all, you would just return the return model to the controller and call the presenter class from there. Any issues with this or can someone explain how this works in MVC?

When implementing Clean Architecture in e.g. Asp.Net MVC what u describe is a perfectly valid, simple and pragmatic approach. Presentation logic is clearly separated from business logic (use cases) and the control flow is according to Uncle Bob's Dependency Rule.
In fact I still follow this approach in my Clean Architecture based Asp.Net MVC projects.
I recently discussed the topic in more depth in a blog post: http://www.plainionist.net/Implementing-Clean-Architecture-Controller-Presenter/

Related

MVC With N-Tier Architecture

I have been jumping between articles and questions but i can't seem to find the information i want.
When i started learning about MVC, tutorials and articles pointed out that:
*Models: is where you business logic goes
*Controller: is where data-access and handling request/respond happens.
I have been working with MVC for a while now and I wanted to migrate an old simple project to MVC. In the project i have a business and data access layers.
After reading about N-Tier MVC architecture, my understanding changed.
The model in which i usually presumed to be the business domain has now changed to be more of a presentation depending on views. Its true that models reflects the business entities but it acts as another layer over it.
So my question here is the following: Assume that i have an MVC project and i have another two projects, business and data-access. Is the relation in this manner right ?
*A model, will mostly have the same properties as in its corresponding business entity.
*The controller will call the DataAccess-Layer to retrieve data, the data will be returned as business object which will be mapped into a model and then returned into a view.
Model not always corresponds to business entities. Because models in MVC used to reflect entities that will be sent to view. So they may be little bit sipmlier than domain business entities. It is correct that your domain model will be mapped to mvc model.
Second statement I agree 100%.
Is the relation in this manner right ?
My answer is that depends on your project scale and team size, But let me explain you my projects architecture.
MVC: A presentation layer, It is the startup project of the application.
Common: This is a class library which contains a set of core classes, such as helpers, base classes, ... This project is referenced to all other projects.
Repositories: For reading from and writing to a database, I've created a project and named it repositories. This project is a combination of repository and the Unit of Work pattern. Implementing these patterns can help insulate your application from changes in the data store.
Test: Unit tests are written in this project.
Hope this will help you.

MVP and model-view communication

First, it is already clear to me that the most important point of MVC is the separation of responsibilities. Lately I have been reading some articles/Q&A in the web to understand the differences between most popular MVC implementations. Examples:
Architecture more suitable for web apps than MVC?
http://joel.inpointform.net/software-development/mvvm-vs-mvp-vs-mvc-the-differences-explained/
If I got it right, people say that the major difference between MVC and MVP is that there is no communication between model and view layers in MVP, controller works as a mediator between both. However, I do not see this restriction in MVP original paper: http://www.wildcrest.com/Potel/Portfolio/mvp.pdf, it just seems to add details to the MVC model, in the form of selections, commands and an interactor.
It seems to me that MVP is just an overloaded MVC acronym which may mean one of two MVC patterns: passive view or supervising controller.
Could someone clarify this?

MVC3 IsValid and Business Logic Layer

I am using MVC3 for my application and I have a question about validation. I have a Business Logic layer that is separate from my web layer where I will have a function like CreateUser, which creates a new user for the application to use. I want this function to be accessible in two places: 1) Somewhere in a controller that makes use of it and 2) in a "Setup Data" program that inserts data into the system.
I want to make use of things like ModelState.IsValid to check for all basic validation, but this won't help me for my Setup Data mode (or any other mode that doesn't go through MVC). Is there any way I can still leverage this code, but to contain all validation in my BusinessLogic layer instead of in the controller without having the BusinessLogic layer rely on MVC?
Thanks.
It looks like this article about Service Layers has what I need. Other suggestions are still welcome. Thanks.
Note that the article on service layers still means that you need a dependency on the MVC assembly. After wrestling a bit with this myself recently, I'm now of the opinion that keeping things as separate as possible is a good design. In my model assembly, I have a services folder wherein from, say, a Create() routine, I validate and throw custom exceptions.
The service layer doesn't care who or how these exceptions are consumed. In your MVC app, map them into model state errors collections or whatever. Your design is all the more solid because your model assembly doesn't depend on some validation runner making appropriate use of MVC validation attributes, collections, etc.
I also noticed the article mentions a repository. I know it's all the rage these days but if you're already using an ORM like Entity Framework, a repository is really just a DAO. Reposity is the new Singleton.

ASP.Net MVC and MVVM

MVVM is a Microsoft design pattern that existed before ASP.Net MVC. Can anyone through light on differences between MVVM and the new MVC pattern?.
Can anyone throw light on differences between MVVM and the new MVC pattern?.
Yes: When using ASP.NET MVC the MVC pattern uses the controller to render the model directly into the view. This is perfectly acceptable for trivial projects with a small number of objects. Where this can become a problem is that the concerns of the UI layer can bleed through to the underlying (domain) model.
When using MVVM then you are adding an abstraction between the Model and the View, which is of course the ViewModel. This allows the author to project into the view an object that is most readily consumed by the view. The ViewModel can contain things which would be out of place in the (domain) Model. The cost associated here is that you need to have mapping logic which transposes the data from the model to the View Model. Tools like AutoMapper can assist with this chore.
A simple example of this might be the Model doesn't require certain fields as required, but a particular View does. Rather than baking this logic into the user interface, if it is attached to the ViewModel, then other UI's can consume the same VM without having to duplicate logic that was baked into the first user interface.
MVC and MVVM are actually quite different. There seems to be a fair bit of misunderstanding of MVVM when talked about with ASP MVC. The practice of making 'View Models' in MVC, which are specific classes to feed views, while good practice is not true to the spirit of MVVM, and in fact is just a cleaner version of MVC.
MVVM is more suited to the desktop using WPF or similar, or purely in the browser using a JavaScript framework such as knockout.js. The pattern is quite different to MVC and involves views being 'subscribed' to the model.
I would venture to suggest that MVVM is Microsoft's design pattern and ASP.NET MVC, which is farily recent, is a specific implementation by Microsoft (that doesn't necessarily adhere to either MVC or MVVM but is similar). And as suggested by Reed, MVC has been around since the 70's.
Both MVC & MVVM are architectural patterns. MVC has its roots way back to Smalltalk. ASP.NET MVC is Microsoft's implementation of the MVC pattern using ASP.NET framework.
Both the patterns deal with separation of concerns. MVC is more to do with the interaction of various commonly used layers in an application like Model (data layer), View (presentation layer) and Controller (business logic layer).
With advanced databinding capabilities of WPF and Silverlight, MVVM was more suited and publicised as the next big thing. Martin Fowler generalized these patterns as presentation patterns in his Enterprise Application Architecture book.
One advantage I see in using a ViewModel is that it allows you to test the application code better using unit tests. Because of this reason I find MVVM or at least the ViewModel bit of it being used quite often in ASP.NET MVC applications as well.

What is an MVC framework and why is it necessary/useful?

I know that an MVC framework allows you to separate business logic, data base access and presentation, but why do we need a framework to do this.
Can't we just keep our classes separated, perhaps using different packages/folders for the model, view and controller classes?
In my opinion the thing you are talking about is the MVC pattern and not a specific framework. Of course you can go and keep all your classes within one project and still use the MVC pattern, as you have all your UI code in the views, the logic in the controllers, ...
A MVC framework on the other hand makes it easier for you to use this pattern. It may provide some base classes for controllers and a mechanism for the communication between view and controller.
I don't know if you are familiar with ASP.NET MVC. The framework itself is very small, but it helps you developing an application with the MVC pattern, as you don't have do think about the previously decribed areas...
Hope this helps
An MVC framework is a framework written to split up the the business logic, database access and presentation.
This is very useful in most web applications, and now lately into software/desktop applications.
This is due to the fact that following the MVC model, your code will be much clearer, cleaner and you keep your application DRY (Do not Repeat Yourself).
You can write your own classes and separate them into Model, View and Control. But again, you will need a framework to help you in accomplishing certain tasks. Like a List control in ASP.NET, or PHP framework being able to help you translate text between languages and so on. (Oh why reinvent the wheel?!)
MVC and framework is a different thing. MVC is just an architectural pattern, which can be applied with any project, with or without framework.
So you don't need a framework to do this. You can separate them by yourself. :)
MVC stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner than the traditional ASP.NET web development. Web applications developed with ASP.NET MVC are even more SEO (Search Engine) friendly.
Developing ASP.NET MVC application requires Microsoft .NET Framework 3.5 or higher.
Model:
MVC model is basically a C# or VB.NET class.
A model is accessible by both controller and view.
A model can be used to
pass data from Controller to view.
A view can use model to display
data in page.
View:
View is an ASPX page without having a code behind file.
All page specific HTML generation and formatting can be done inside view.
One can use Inline code (server tags ) to develop dynamic pages.
A request to view (ASPX page) can be made only from a controller’s action method
Controller:
Controller is basically a C# or VB.NET class which inherits system.mvc.controller.
Controller is a heart of the entire MVC architecture.
Inside Controller’s class action methods can be implemented which are responsible for responding to browser OR calling views.
Controller can access and use model class to pass data to views
Controller uses ViewData to pass any data to view.
MVC is a code organization architecture style to organize your code-logic in a meaningful way for web applications. As a programmer I have almost puked when I have inherited other people's code when their code logic is all over the place and following their web application code turns into following a rabbit down the gutter hole. Why MVC? hmm.. well why should I use a filing cabinet or folders to organize my plethora of paper and not just have my papers stashed in a large pile and have others figure how they connect to each other. It increases code readability. With MVC it becomes very easy to follow code logic since you are following standard structure for a web application. Business logic is separated out from UI. Easier to delegate work decouple work on a project.
You can of course approach it yourself by segregating your classes. A framework supplies common scaffolding that you wouldn't have to build yourself. But it will also impose some structure on your code. You'll have to evaluate whether the framework helps more than it hurts.
You are correct, there are strategies that you can implement to help with separation of concerns without using MVC.
Microsoft's ASP.NET MVC framework is one strategy that can be employed, and that is what I think you are asking about.
This MVC framework makes such separation of concerns easy.
The other major advantage of MVC is testability - (depends on whether you believe in unit testing - I do).
The MVC framework ensures that all orchestration logic is on your controllers and through the FormControls collection allows full unit testing of all aspects of your application except for how it is presented.
As the MS MVC framework encourages adherence to common rules and structure of the application which should lead to greater maintainability.
The major downside of MVC is the code-in-front code weaving required for presentation, but this can be easily overcome.
Perhaps this is just a linguistic thing. I've seen "frameworks" referring to themselves as a DSL -- Domain Specific Language.
And you don't need a framework But here's something to consider: You already know for a web app you're going to want to do a few common things... route URLs, render pages, etc. Why re-write it all? For other problem domains you'll have generic things to do as well.
Hai Friends There are somemany types of architecture frame work has been there,firstly i know 2tier and 3 tier frame work ,the 3 tier and mvc ,entity framework are same but in different name's,so study a good background in any one architecture there fore if you went to any multinational companies ,you can easly score/highlight to your carrer.
Model View Controller or MVC as it is popularly called, is a software design
pattern for developing web applications. A Model View Controller pattern is made
up of the following three parts:
**Model** - The lowest level of the pattern which is responsible for maintaining data.
**View** - This is responsible for displaying all or a portion of the data to the user.
**Controller** - Software Code that controls the interactions between the Model and View

Resources