I heard that controller belongs to the presentation layer. How is it possible?
I thought that :
Is there good link to prove that controller belongs to the presentation layer?
"Spring MVC is used for presentation layer": how can we use MVC only in the presentation layer?
The presentation layer contains views and controllers.
You must not mistake an MVC architecture for a multitier/layer architecture (especially a 3-tier architecture). Most of the time Model/View/Controller is not the primary design of a web application, it is just a subset of a multitier/layer architecture.
Take a look at this oversimplified scheme (you could have the DAOs in a dedicated Data Access Layer, but this is not important in this post) :
Spring MVC is a presentation framework : it deals with controllers and views. But why the "M" in Spring MVC ? Just because, as many other presentation framework, it naturally deals with a representation of a model/entity ("M"). This representation is the one used in your controllers, displayed in your views, submitted in your forms, etc. That's why the framework is called Spring MVC, even if the model/entity is not part of the prensentation layer.
I think it is a good name for this Framework, because it is really "MVC" oriented. Indeed the representation of a model/entity can be :
Spring's recommendation is to directly use the model/entity ("M") object :
Reusable business code, no need for duplication. Use existing business objects as command or form objects instead of mirroring them to extend a particular framework base class.
That's why I say the framework is very "MVC" oriented, compared to others, like Struts, where you have to use different form objects.
Some interesting links :
The controller controls the presentation layer logic. For all the business code, transactional use cases, persistence, etc., it typically delegates to a service layer.
A typical way of doing that is to implement transactional services as spring beans and inject those spring beans in controllers. Typical use case: create a new product:
It largely depends on what flavor of MVC you're using, and what environment you're using it in.
For example, ASP.NET MVC is entirely a UI pattern, so all three parts are part of presentation.
However, in most implementations of MVC, the Controller interacts with the user, and thus is part of the UI layer. It may handle button presses, and keyboard input... but in many cases, the controller is also responsible for connecting the Model and the View together.
The one universal truth is that you should NOT be doing business logic in the controller if you cannot help it. Where the business logic exists depends on many factors. It might be part of the model in some implementations, or it may be it's own separate layer outside of MVC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With