What is an MVC design pattern
Next:Singleton pattern Up:Basics of patterns Previous:Observer Pattern & nbsp Contents & nbsp index
The abbreviation MVC stands for Model-View-Control. The MVC pattern is actually relatively simple. It says that a program is divided into three different parts. (see figure 4.2)
The model part contains the data and the data access. Classic objects of an object-oriented program could be located here, as well as database access or any other type of data management.
There is also the view section. All views of the program are located here. These normally show the data of the model and are implemented completely independently of the data.
The third part of the pattern is the control part. This includes all control options with which a user can control the program. This part is also usually completely independent from the other parts.
In some programming languages or applications you are forced to accommodate the view and the control part in one structure. This pattern is then referred to as the document view model.
In an implementation of the MVC pattern, the individual sub-areas usually only have references to the other sub-areas. Only the defined access methods are used. It is therefore not possible, for example, to access objects of the model class directly from a view class.
In the following example a program is presented which not only implements an MVC design pattern, but also uses an observer pattern at the same time. This mixing of the two design patterns is very common because they go well together. The two are linked in such a way that the view classes are the observer classes of the observer pattern and the model class represents the subject class of the pattern.
The source code shown here contains a class Model. This class represents the model class of the MVC pattern and at the same time the subject class of the observer pattern. It therefore contains all data or references to data and manages a list with all observers. There is also the Control class, which of course represents the control area of the MVC pattern. Such a class can be used, for example, to make changes to the model. However, these are only possible via access methods implemented by the model class. Then there are the ButtonView and RealView view classes. These implement the view interface, which is to be equated with the observer interface of the observer pattern. Since you implement this interface, you can register with the model and you will be notified of data changes. The RealView then has the option of displaying the data of the model updated as soon as it changes. The ButtonView contains only one button, which uses the control class to change the data in the model.
So you can see that although all classes are related, they are implemented independently of each other. This allows the program to be expanded later with additional controls or views without affecting the integrity of the program.
Next:Singleton pattern Up:Basics of patterns Previous:Observer Pattern & nbsp Contents & nbsp index Rainer Friesen, Markus Stollenwerk and Daniel Valentin, 2007-03-06
- Who is the tallest man in the world
- What is the chemical formula of Hexadecyne
- Where is the supremacy clause now?
- What is an offensive marketing strategy
- Who is JP Morgan
- Who sang the song Real Cool Time
- Why are these cells called specialized cells
- How do people unconsciously communicate
- How profitable can blogs get over time
- Who was the best Indian king
- How did quitting social media affect you
- How to write sanish in chinese
- Can you cure a headache
- How big is a 2-story house
- How can I create a website application?
- What political system does Israel have
- Which oil corresponds to Saffola
- What are the best ingredients for natural oil
- Why do we use a ballpoint pen
- Where can I change currency in London?
- Why does Gaehn feel so good?
- How does an optimizer SQL
- Mint com has an open API
- How can I start an orchard?
- Will the Italian cypress grow in the shade
- What is an air conditioning wall sleeve
- What is anycast
- How many over 50 people read blogs
- What are monitor PCs
- What neighborhood is Notre Dame in
- What gives Laksa its red color
- Iran is suffering from some environmental disasters
- How to translate slang into other languages
- Why don't people trust the actors