SlideServe
Menu
Préférences
© SlideServe · v2026

What is MVC

elmo avatar
9 diapositives · 257 Views · Mar 27, 2014

What is MVC. Category: System MVC=Model-View-Controller Model: The data being maintained by the application (in the form of an object or objects) View: The presentation of the data Controller: The changing of data based on user inputs.

What is MVC - slide 1
01 / 9What is MVC
1 / 17

Télécharger la présentation

What is MVC
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. What is MVC • Category: System • MVC=Model-View-Controller • Model: The data being maintained by the application (in the form of an object or objects) • View: The presentation of the data • Controller: The changing of data based on user inputs. • Logically separates object data itself (model), from the presentation logic (view) and modification logic (controller) for that data.

  2. MVC Background • MVC often relies on two other patterns: Strategy & Observer • About Strategy: • Category: Behavioral • Strategy objects represent some logic to be performed • By being stored in separate objects, the logic is pluggable, simply by swapping out the strategy object being used. • Usually, the Controller part of MVC is implemented as a Strategy object to simplify choosing controllers • About Observer: • Category: Behavioral • Often a change to data requires a large number of disparate changes to occur (update 2 screens, send an email, save something to a file, etc). • The observer pattern provides a generic format to notify many observers in a change to an observable • The observable object, when changed, notifies all observer objects that it was changed, allowing each in turn to perform some functionality. • Usually, the model part of MVC is implemented as observable (the object to be watched), and the views are implemented as observers (the objects to do the watching); therefore when the model changes, the views are automatically updated.

  3. How to Use MVC • Create a model object to represent your data. • * Implement the observer pattern with your model to make updating the view objects more intuitive. • Create 1-many views that represent the model object, and potentially some functionality (such as editing) • Create 1-many controllers that represent the functionality for any views with controls on them. • * Implement the strategy pattern with your controllers to make them easily pluggable into the view. • * - Denotes an optional step

  4. Component DiagramNote: A component diagram and subsequently, components, are used to describe this pattern (as opposed to classes) because the model, controller, and view may not be one object, but a combination of many. From (Stephen Stelting, Olav Maassen, Applied Java™ Patterns)

  5. Class Diagram (Strategy) From (Stephen Stelting, Olav Maassen, Applied Java™ Patterns)

  6. Class Diagram (Observer) From (Stephen Stelting, Olav Maassen, Applied Java™ Patterns)

  7. Why MVC • MVC ensures that the three different components (model, view, and controller) are loosely coupled • Different views, and different controllers can be plugged in easily. • Not only can views differ in terms of functionality, they can also differ in terms of platform (Swing, console, web page, etc.)

  8. All-in-one Heavyweight Class public class Contact { // … instance variables // … getter/setter methods public void renderDisplayView() { // render display } public void renderEditView() { // render edit view // connect buttons/fields to this class } public void handleEdit(…) { // handle edit } } Modular, Lightweight Classes public class Contact { // … instance variables // … getter setter methods. } public interface ContactView { public void render(); } public class DisplayContactView { public void render() { // render display view… } } public class EditContactView { public void render() { // render edit view // connect buttons/fields to controller } } public interface ContactController { public void handle(…); } public Class EditContactController { public void handle() { // handle edit… } } ExampleLet’s say we are creating a program to manage contact information...

  9. Full Swing ExampleFrom (Stephen Stelting, Olav Maassen, Applied Java™ Patterns) (See associated .java files)