Professional Documents
Culture Documents
MVC Rest Gdata
MVC Rest Gdata
It facilitates reuse
Wendy Liu
CSC309F – Fall 2007 http://java.sun.com/developer/technicalArticles/javase/mvc
1 2
Model
Views
VIEW
State Change
State
Query Change
Notification
User
Gestures
A = 50%
View Controller
Model
B = 30% View
C = 20% Selection
Method invocations
3 Events 4
1
Model View
Represents application data and business rules Renders the contents of a model
that govern access to and updates of this data Specifies how the model data should be presented
In enterprise software, a model often serves as a When the model changes, the view must update its
software approximation of a real-world process presentation
Notifies views when it changes and enables push model
the view registers itself with the model for change notifications
the view to query
pull model
Allows the controller to access application the view is responsible for calling the model when it needs to
functionality encapsulated by the Model retrieve the most current data
Forwards user gestures to the controller
5 6
Method invocations
7 Events 8
2
Best Practices: MVC Separation Interaction between MVC Components (1)
Organize model elements, views and controller Once the model, view, and controller objects are instantiated,
actions into “physically” separate: the following occurs:
Source code units
Source code packages
1. The view registers as a listener on the model
Any changes to the underlying data of the model immediately
Benefits: result in a broadcast change notification, which the view receives
Helps enforce logical separation of concerns
This is an example of the push model described earlier
In a large project, a developer with specialized skillset
The model is not aware of the view or the controller
may work on just one of M, V or C
It simply broadcasts change notifications to all interested listeners
Simplifies maintenance, e.g. porting app to new platform
Frameworks that emphasize MVC separation: 2. The controller is bound to the view
Apache Struts I.e., any user actions that are performed on the view will implicitly
invoke a registered event listener method in the controller class
JavaServer Faces
Ruby on Rails 3. The controller is given a reference to the underlying model
9 10
11 12
3
Known Examples
A few well-known examples of RESTful, resource-oriented
web services include:
Services that expose the Atom Publishing Protocol
Lecture 16b: RESTful,
http://bitworking.org/projects/atom/draft-ietf-atompub-protocol-04.html
Atom’s variants such as GData
Resource-Oriented Web Services http://code.google.com/apis/gdata/
Amazon’s Simple Storage Service (S3)
http://aws.amazon.com/s3
Wendy Liu Most of Yahoo!’s web services
http://developer.yahoo.com/
CSC309F – Fall 2007 Most other read-only web services that don’t use SOAP
Static web sites
Many web applications, especially read-only ones like search
engines
1 2
1
Actions (Verbs) Example: Turn On Light
Controllers cannot have arbitrary verbs, only
these: RPC style:
POST proxy.turnLightsOn(“ba2185”);
Create - create a new resource
GET
Retrieve - retrieve a representation of a resource
REST style:
PUT
Update - update a resource PUT http://control.com/ba2185/lights HTTP/1.1
DELETE
Delete - delete a resource on
5 6
7 8
2
What is REST Key Constraints
An architectural style for distributed Client server style
hypermedia systems Separating the user interface concerns from the
data storage concerns
Stateless
Server keeps no session state (only resource state)
Each request from client to server must contain
all of the information necessary to understand
the request
Cannot take advantage of any stored context on
the server
9 10
11 12
3
Lecture 16c: Web Services
GData
for A3
1 2
3 4
1
Atom GData
Atom is designed to be a universal publishing A GData feed conforms to either the Atom or RSS
standard for personal content and weblogs syndication formats
Atom is the default underlying data format for Google
The Atom Syndication Format is an XML web services
language used for web feeds To acquire information from a service that supports
GData, you send an HTTP GET request; the
service returns results as an Atom or RSS feed
You can update data (where supported by a
particular GData service) by sending an HTTP PUT
request
http://code.google.com/apis/gdata/reference.html
5 6
Google Calendar
Feeds are not essential for calendar service
Google provides it as a platform for all its web services
Google calendar gadget
Calendar feeds
metafeed
allcalendars
owncalendars
event
Requesting a representation
user ID (or default)
visibility (private, public)
projection (full, full-noattendees, composite, attendees-only, free-busy,
basic)
http://www.google.com/calendar/feeds/default/private/full
7