Programming in Java CSCI 2220 - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Programming in Java CSCI 2220

Description:

Windows Explorer provides a 'view' of the file system. Multiple different views represent the same file system in different ways using the split panes ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 8
Provided by: owenke
Category:
Tags: csci | java | programming | view

less

Transcript and Presenter's Notes

Title: Programming in Java CSCI 2220


1
Programming in JavaCSCI 2220
  • Model-View-Controller (MVC)
  • Design Pattern

2
MVC Design Pattern
  • Many typical GUI applications consist of views
    of some particular application state or model
  • The GUI also includes mechanisms to manipulate or
    control the models state
  • This allows the application data to be completely
    independent of the GUI design and also allows for
    multiple GUI views to represent the same model
    data in multiple different ways

3
Example Application
  • Windows Explorer provides a view of the file
    system
  • Multiple different views represent the same file
    system in different ways using the split panes
  • The application provides mechanisms to manipulate
    the file system. These mechanisms are
    representative of the controller in the MVC
    pattern

4
MVC Structure
  • Model
  • Represents application state
  • Exposes operations that can be performed on the
    model to the controller
  • Notifies all registered views when changes to
    the model are made

State Change Requests
State Change Notifications
  • Controller
  • Provides an interface between the model and the
    view to facilitate user modifications
  • Responds to user actions by notifying model of
    desired changes
  • View
  • Displays the model
  • Responds to notifications from the model by
    updating the display

Often Combined as GUI elements
5
MVC Pattern in Java
  • Java provides a built in framework to facilitate
    the use of the MVC design pattern
  • Your model must extend the Observable class
  • Your views should implement the Observer
    interface
  • One method public void update(Observable o,
    Object arg)
  • Called by Observable objects for which the
    Observer is registered with
  • The Observable class contains methods to
    facilitate adding Observers (views) to the model
    and also mechanisms to automatically notify all
    Observers that have been added when the model has
    changed

6
Notes
  • The Observer/Observable framework combines the
    view and the controller of the MVC pattern into
    one class (the Observer class)
  • The Swing framework uses a similar modified MVC
    design structure (not Observer/Observable but
    most Swing components have an accessible model
    which is independent of the GUI component
    visualization implementation)
  • For example JSlider is a GUI component that
    represents a user modifiable slider. The
    BoundedRangeModel class is its corresponding
    view class and each JSlider has a corresponding
    and user-definable BoundedRangeModel associated
    with it

7
Homework
  • Homework 6 due tonight at 1155 PM
  • Final Project will be posted online soon
  • Due May 4
Write a Comment
User Comments (0)
About PowerShow.com