2

So usually when working with the MVC you have a controller that controls the input a model that process it and makes it ready for the user and a view that display the "result" to the user.

Now when creating this pattern you seperate the code into their relevant place. for instance the controller code goes into the controller, the gui code goes into the view and so on.

Now my question is if we look at all of the design patterns out there for instance the observer pattern. How would you apply such pattern to a code structure that already implements the MVC pattern? for that case many of the other patterns aswell such as composite, factory and command pattern?

Doesnt the structure of the MVC pattern make it harder to implement other good pratice design patterns?

Gordon
  • 312,688
  • 75
  • 539
  • 559
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364

5 Answers5

3

MVC is not a Design Pattern, it's an Architecteral Pattern.

Wikipedia :

An architectural pattern is a standard design in the field of software architecture. The concept of an architectural pattern has a broader scope than the concept of design pattern. The architectural patterns address various issues in software engineering, such as computer hardware performance limitations, high availability and minimization of a business risk. Some architectural patterns have been implemented within software frameworks.

So it's not fair to compare MVC with design patterns. Design patterns can be implemented on each of these logical modules (Model, View and Controller)

rai.skumar
  • 10,309
  • 6
  • 39
  • 55
0

You can have other patterns in your views. For example, you could use the mediator pattern to communicate between modules or views in your javascript. You could also use the observer pattern, too.

Here is a video of a presentation given by Nicholas Zakas on how to use the sandbox pattern. It is very similar to the mediator pattern, but it is a little more complex and it allows you to create modules that are even more loosely coupled. http://www.youtube.com/watch?v=7BGvy-S-Iag

This can be implemented in javascript while still using the mvc pattern. For example, you could use this with Rails, which naturally forces mvc by convention.

Edit: Technically, Rails is not MVC, but you get the idea. More information on that here: What is MVC in Ruby on Rails?

Community
  • 1
  • 1
Spencer
  • 1,527
  • 1
  • 10
  • 23
  • -1 Rails does not implements MVC. Instead it is a rapid prototyping framework, that uses some of the terms from the pattern, but has dumbed them down to the point at which they break SoC principle. It's a wonderful framework for prototying, but not something you would want at the scales of codebase, which would require use of MVC. – tereško Aug 06 '13 at 15:27
  • @teresko, While I don't disagree with you, Rails is widely considered to be MVC and while technically it is considered "Model 2", I don't think that my stating Rails is MVC detracts from my answer to the question. – Spencer Aug 08 '13 at 15:42
  • **Rails is NOT Model2!** You do not even understand what Model2 MVC is. What rails implements is an extremely simplified (more like - completely broken) version of [PAC](https://en.wikipedia.org/wiki/Presentation-abstraction-control). Since "presentation" has been replaced with templates and "abstraction" - with active record (which suffers from several major violations of OOP principles). – tereško Sep 08 '13 at 12:44
0

MVC is an architectural pattern. Like all architectural patterns it is made up of several design patterns. The relationship between views and models is the Observer Pattern. Controllers are interchangeable strategies of the views. And the views are using the Composite Pattern.

Those are only the core patterns of MVC. The model is often a Mediator and the Views may contain Decoratoras for example. Views can create controllers using Factory Method.

MarcB
  • 104
  • 2
0

Under MVC, the observer pattern can be used to coordinate communication between different elements of your model.

For instance, suppose one core model component generates data and needs to notify other model components. You can facilitate this communication by registering the other models as listeners on the core model.

This behavior is independent of anything occurring in the view and controller layers.

0

No. It does no negate other object oriented and functional programming patterns.

MVC is an architectural design pattern, that you use on top of your existing codebase, when the pure OOP practices are not enough anymore to keep the code manageable.

The MVC pattern introduces additional constraints, that lets you organize the code and flow of information between the parts of your code.

tereško
  • 58,060
  • 25
  • 98
  • 150