observer pattern vs MVC

25,675

Solution 1

  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

Solution 2

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.

Share:
25,675
Alex
Author by

Alex

Updated on June 21, 2020

Comments

  • Alex
    Alex almost 4 years

    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?

  • whomaniac
    whomaniac about 9 years
    I see a loop here. View sends signal to controller that sends signal to a model that sends a signal to view??
  • stackexchanger
    stackexchanger over 8 years
    Yes. A signal starts and stops at the view. For example, if you click a button to italicize text, the view tells the controller, which decides what "italicization" means (logic, e.g. is any text actually selected), then updates the text model (set that block of text to "ITALIC=TRUE"), which tells the view to display the italic version of the font. Generally you don't want an infinite loop though.
  • binaryguy
    binaryguy over 8 years
    But if the update comes from the Model what does the arrow "View Selection" do?