0

MVC only models the presentation layer

I don't understand this statement. MVC splits the application into Model, View and Presentation. Isn't that all the layers required for an application to be complete?

I mean, when building a MVC application, what other layers are there that are outside the MVC's scope that are necessary and do indeed communicate with the "presentation" layer?

microwth
  • 642
  • 9
  • 22
  • 2
    The M, V and C are really all part of the presentation layer. As for what the other layers are, it depends on your design pattern. You may need a service layer, data payer, domain layer, infrastructure layer etc. None of those other layers should know anything about presentation. – DavidG Jan 28 '19 at 15:45
  • isn't Model the Data layer? – microwth Jan 28 '19 at 15:46
  • 1
    No, those models are really the presentation models (often called "view models"). Your data layer should contain it's own models. While you can spit out data models directly into your views, it's really not a good idea. – DavidG Jan 28 '19 at 15:47
  • 3
    @microwth: It can be in simple scenarios. For example, in a simple ASP.NET MVC app you can write some model classes and let Entity Framework handle the data access for you. This obscures the data layer and assumes the data models and the presentation models are the same, which they might indeed be in simple applications. Depends on the system and the various architectural needs to be addressed. – David Jan 28 '19 at 15:48
  • 2
    Consider a pattern like domain driven design (aka DDD), in that style of development you might have data models, domain models and view models. It helps massively with things like separation of concern. – DavidG Jan 28 '19 at 15:50
  • where do you keep the business logic? – microwth Jan 28 '19 at 15:50
  • 1
    Depends on the pattern you use. In DDD business logic is referred to as domain logic and, funnily enough is kept in the domain layer. – DavidG Jan 28 '19 at 15:51
  • @DavidG in MVC? is that property of the Controller or the Model? – microwth Jan 28 '19 at 15:52
  • It can be, but I would strongly recommend you don't do that. – DavidG Jan 28 '19 at 15:52
  • @DavidG which one? the Controller? – microwth Jan 28 '19 at 15:53
  • I don't get the question. Either way, this discussion is off topic here, I suggest you go read up on a few patterns. Try out DDD, it's a good style to use. – DavidG Jan 28 '19 at 15:54
  • @DavidG I mean, what is the "It can be" you've said referring to? – microwth Jan 28 '19 at 15:57
  • You asked where to keep business logic, I'm saying it should be outside of the entire MVC project. – DavidG Jan 28 '19 at 15:59
  • Voted to close as opinion based. To answer this question, you'd have to decide on which layers you actually want to implement which is going to differ from dev to dev. Some devs may only use presentation and service layer with the service layer being able to query the db, some devs may only use presentation and data layer with the presentation layer having business logic in it, some may use pres layer, service layer and data layer or some may put everything in the presentation layer. It all depends on the architecture YOU decide is best fit for the project – GregH Jan 28 '19 at 16:13
  • @microwth MVC was originally developed for desktop apps, with separation of concerns in mind. In time, people tried to apply such separation in web apps as well. Though adaptations were necessary, leading to a multitude of patterns: MVVM, MVP, MVC Model 2, etc. So: MVC is not MVVM or MVP or etc. But all these approaches have this in common: the separation of concerns happens by separating only two layers from each other: the model layer (including business logic) and the delivery mechanism (the layer involving any other components responsible to transfer data between user and model layer). – dakis Jan 28 '19 at 17:54
  • @microwth Some links: [this](https://stackoverflow.com/a/5864000/9455607), [this](https://stackoverflow.com/a/3540895/9455607), [this](https://stackoverflow.com/a/54203726/9455607). – dakis Jan 28 '19 at 18:03

0 Answers0