Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

observer pattern vs MVC [closed]

I am wondering what are the differences between an observer pattern and MVC. I have some experiences writing MVC program in Java at school, but no experience with observer pattern. (someone told me that observer pattern means I used the Observer class in Java... I don't think that's a good answer.)

Please help me with the following questions, thanks a lottttt.

  1. What is the difference between them? The observer pattern does not uses a separate class for controllers?

  2. What is the relationship between observer pattern and MVC? I heard two different versions.

    • First version is that, MVC is an architecture and Observer Pattern is an design pattern. They look similar because MVC uses the observer pattern.
    • Second version is that, observer pattern and MVC is two different design patterns.
  3. Is it possible to use only one of them? If so, in what cases, you uses one over the other and why?

like image 773
Alex Avatar asked Mar 22 '13 04:03

Alex


2 Answers

  1. You are right in saying that MVC is more a architecture style rather than a design pattern good discussion here : Is MVC a Design Pattern or Architectural pattern

I hope this answers Your other two question too.

Observer Design pattern is a Behavioral pattern which is used when we want to notify all of the dependents of an object(say x) in the event of change of the object x. Good read: http://www.dofactory.com/Patterns/PatternObserver.aspx

And they both are closely related, as MVC you would see from MVC diagram - for example: A Change in 'View' Has to be notified to 'Model' and 'Controller' One efficient way to achieve such feature is Observer design pattern.

Good read: http://en.wikipedia.org/wiki/Observer_pattern

In fact the observer pattern was first implemented in Smalltalk's MVC based user 
interface framework.

Hope this helps!

enter image description here

like image 188
prashantsunkari Avatar answered Nov 15 '22 15:11

prashantsunkari


There's a lot of articles related with the questions you are asking. MVC to me is an architectural pattern where it "contains" the observer pattern as well. I believe if one really study the MVC pattern in different real-life projects implementation, there are more than one design pattern in it.

It's either you zoom in, or zoom out.

like image 23
CalebC Avatar answered Nov 15 '22 14:11

CalebC