MVC vs Observer
-
wrote on 27 Oct 2012, 22:01 last edited by
Can anyone explain the similarities and differences between the mvc pattern and the observer pattern and how they are implemented within the Qt framework?
-
wrote on 17 Jun 2013, 11:02 last edited by
The MVC pattern aims
at separating
the data (model)
the visualization (view)
modification (controller)Provides clear responsibilities for all classes involved
Observer Pattern - When writing event-driven programs, GUI views need to respond to changes in the state of data model objects, so that they can display the most recent information possible.
When a particular subject object changes state, it needs an indirect way to alert (and perhaps send additional information to) all the other objects that are listening to state-change events, known as observers. A design pattern that enables such a message-passing mechanism is called the Observer pattern, sometimes also known as the Publish-Subscribe pattern.
There are many different implementations of this pattern. Some common characteristics that tie them together are
They all enable concrete subject classes to be decoupled from concrete observer classes. They all support broadcast-style (one to many) communication. The mechanism used to send information from subjects to observers is completely specified in the subject's base class.
Qt's approach is very different from Java's approach, because signals and slots rely on generated code, while Java just renames observer to listener.