<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: AJAX and the clean Model-View-Controller</title>
	<atom:link href="http://parand.com/say/index.php/2005/09/07/ajax-and-the-clean-model-view-controller/feed/" rel="self" type="application/rss+xml" />
	<link>http://parand.com/say/index.php/2005/09/07/ajax-and-the-clean-model-view-controller/</link>
	<description>Parand Tony Darugar: A Cruel and Petty Dictator</description>
	<lastBuildDate>Tue, 17 Jan 2012 23:10:42 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ryan Brown</title>
		<link>http://parand.com/say/index.php/2005/09/07/ajax-and-the-clean-model-view-controller/comment-page-1/#comment-88141</link>
		<dc:creator>Ryan Brown</dc:creator>
		<pubDate>Fri, 28 Sep 2007 05:31:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.parand.com/say/index.php/2005/09/07/ajax-and-the-clean-model-view-controller/#comment-88141</guid>
		<description>I am by no means a master of MVC, but three things jumped out at me as I read your post. My responses come from a book called &lt;a href=&quot;http://www.amazon.com/Pattern-Oriented-Software-Architecture-System-Patterns/dp/0471958697&quot; rel=&quot;nofollow&quot;&gt;&quot;A System of Patterns&quot;&lt;/a&gt;.

1. You said, &quot;First, thereâ€™s the issue of what to model in the Model. Do I model the back-end data/services/objects or the UI data model? Note that these are different. The UI model is inherently about whatâ€™s being displayed. The back-end model is about the inherent behavior of the back-end system.&quot; A System of Patterns says that the Model contains the &quot;functional core of the application&quot; (p 127), encapsulating the appropriate data and providing methods that do app specific processing. The way I read this, the Model does not model the UI at all. The UI is actually the Controller component of the MVC pattern. &quot;The user interacts with the system solely through Controllers&quot; (p 127). If you have 10 different UIs relying on the same back-end (Model component), then you&#039;ll be writing 10 different Controllers.

2. You said, &quot;What is the View, exactly? In the Web world I tend to think of the View as the HTML.&quot; Precisely. The HTML is a View of the data stored in the Model component. It&#039;s true that there may be buttons, text fields, forms, etc. displayed in the HTML, but as soon as a user clicks on something the Controller component is in charge. Perhaps that&#039;s where some confusion creeps in... The View component must collaborate with both the Model and Controller components and therefore will display information from both. Further, &quot;there is a one-to-one relationship between views and controllers.&quot; (p 128) You have exactly one Model component (your back-end) and an equal number of View and Controller components (displays and UIs).

3. You said, &quot;How about the Controller? This one becomes a little more cloudy for me in practice, because Iâ€™ve separated out the View completely, so really Iâ€™m controlling my back-end state. Which is different from controlling my View state. It becomes more an issue of validating that the state as I know it on the back-end is the same as the state on the front-end. Or, more acurately, to validate that the state transitions the front-end requests are acceptable to the back-end.&quot; Again, you are on the right track. The Controller component, which is really the functional element of the UI (the visual element being handled by the View component) is a messenger. User clicks a button, so the Controller takes that information back to the Model to either update the Model with new data and/or grab some data from the Model to be displayed. There&#039;s your state change. The Controller component works in both directions. Changes to the Model component are communicated to View components via corresponding Controller components. Changes in a View Component are immediately handled by the corresponding Controller component (which is the UI, after all) and communicated to the Model component.

There is one major piece to this pattern that you don&#039;t mention but which seems integral. &quot;The separation of the model from view and controller components allows multiple views of the same model. If the user changes the model via the controller of one view, all other views dependent on this data should reflect the changes.&quot; (p 127) You have, I think, pretty much implied this in your post, but here&#039;s the additional bit... &quot;The model therefore notifies all views whenever its data changes. The views in turn retrieve new data from the model and update the displayed information.&quot; (p 127). So, there&#039;s has to be a notification mechanism in place to keep everything synched up. State change must be communicated through the whole application. The book suggests that a registry be kept of all dependent components. Whenever a View is created a Controller will also be created (one duty of a View component is to create and initialize a corresponding Controller), it needs to register itself with the application, so that it can be notified when something changes.

One more thing. It is possible to completely separate your HTML and your JavaScript. The following chunk is from JavaScript - The Definitive Guide, 5th edition

--- begin chunk ---
Unobtrusive JavaScript

A new client-side programming paradigm known as unobtrusive JavaScript has been gaining currency within the web development community. As its name implies, this paradigm holds that JavaScript should not draw attention to itself; it should not obtrude.[*] It should not obtrude on users viewing a web page, on content authors creating HTML markup, or on web designers creating HTML templates or CSS stylesheets.

[*] &quot;Obtrude&quot; is an obscure synonym for &quot;intrude.&quot; The American Heritage dictionary cites: &quot;To impose... on others with undue insistence or without invitation.&quot;

There is no specific formula for writing unobtrusive JavaScript code. However, a number of helpful practices, discussed elsewhere in this book, will put you on the right track.

The first goal of unobtrusive JavaScript is to keep JavaScript code separate from HTML markup. This keeps content separate from behavior in the same way that putting CSS in external stylesheets keeps content separate from presentation. To achieve this goal, you put all your JavaScript code in external files and include those files into your HTML pages with  tags (see Section 13.2.2. for details). If you are strict about the separation of content and behavior, you won&#039;t even include JavaScript code in the event-handler attributes of your HTML files. Instead, you will write JavaScript code (in an external file) that registers event handlers on the HTML elements that need them (Chapter 17 describes how to do this).

As a corollary to this goal, you should strive to make your external files of JavaScript code as modular as possible using techniques described in Chapter 10. This allows you to include multiple independent modules of code into the same web page without worrying about the variables and functions of one module overwriting the variables and functions of another.

The second goal of unobtrusive JavaScript is that it must degrade gracefully. Your scripts should be conceived and designed as enhancements to HTML content, but that content should still be available without your JavaScript code (as will happen, for example, when a user disables JavaScript in her browser). An important technique for graceful degradation is called feature testing: before taking any actions, your JavaScript modules should first ensure that the client-side features they require are available in the browser in which the code is running. Feature testing is a compatibility technique described in more detail in Section 13.6.3.

A third goal of unobtrusive JavaScript is that it must not degrade the accessibility of an HTML page (and ideally it should enhance accessibility). If the inclusion of JavaScript code reduces the accessibility of web pages, that JavaScript code has obtruded on the disabled users who rely on accessible web pages. JavaScript accessibility is described in more detail in Section 13.7.

Other formulations of unobtrusive JavaScript may include other goals in addition to the three described here. One primary source from which to learn more about unobtrusive scripting is &quot;The JavaScript Manifesto,&quot; published by the DOM Scripting Task Force at http://domscripting.webstandards.org/?page_id=2.

--- end chunk ---

Food for thought?

Thanks for the post. I am currently working on a design for a very simple AJAX app and came across this when googling for &quot;ajax model view conroller&quot;. Attempting to answer your questions helps me get a better grasp on the MVC pattern.

Cheers,
Ryan</description>
		<content:encoded><![CDATA[<p>I am by no means a master of MVC, but three things jumped out at me as I read your post. My responses come from a book called <a href="http://www.amazon.com/Pattern-Oriented-Software-Architecture-System-Patterns/dp/0471958697" rel="nofollow">&#8220;A System of Patterns&#8221;</a>.</p>
<p>1. You said, &#8220;First, thereâ€™s the issue of what to model in the Model. Do I model the back-end data/services/objects or the UI data model? Note that these are different. The UI model is inherently about whatâ€™s being displayed. The back-end model is about the inherent behavior of the back-end system.&#8221; A System of Patterns says that the Model contains the &#8220;functional core of the application&#8221; (p 127), encapsulating the appropriate data and providing methods that do app specific processing. The way I read this, the Model does not model the UI at all. The UI is actually the Controller component of the MVC pattern. &#8220;The user interacts with the system solely through Controllers&#8221; (p 127). If you have 10 different UIs relying on the same back-end (Model component), then you&#8217;ll be writing 10 different Controllers.</p>
<p>2. You said, &#8220;What is the View, exactly? In the Web world I tend to think of the View as the HTML.&#8221; Precisely. The HTML is a View of the data stored in the Model component. It&#8217;s true that there may be buttons, text fields, forms, etc. displayed in the HTML, but as soon as a user clicks on something the Controller component is in charge. Perhaps that&#8217;s where some confusion creeps in&#8230; The View component must collaborate with both the Model and Controller components and therefore will display information from both. Further, &#8220;there is a one-to-one relationship between views and controllers.&#8221; (p 128) You have exactly one Model component (your back-end) and an equal number of View and Controller components (displays and UIs).</p>
<p>3. You said, &#8220;How about the Controller? This one becomes a little more cloudy for me in practice, because Iâ€™ve separated out the View completely, so really Iâ€™m controlling my back-end state. Which is different from controlling my View state. It becomes more an issue of validating that the state as I know it on the back-end is the same as the state on the front-end. Or, more acurately, to validate that the state transitions the front-end requests are acceptable to the back-end.&#8221; Again, you are on the right track. The Controller component, which is really the functional element of the UI (the visual element being handled by the View component) is a messenger. User clicks a button, so the Controller takes that information back to the Model to either update the Model with new data and/or grab some data from the Model to be displayed. There&#8217;s your state change. The Controller component works in both directions. Changes to the Model component are communicated to View components via corresponding Controller components. Changes in a View Component are immediately handled by the corresponding Controller component (which is the UI, after all) and communicated to the Model component.</p>
<p>There is one major piece to this pattern that you don&#8217;t mention but which seems integral. &#8220;The separation of the model from view and controller components allows multiple views of the same model. If the user changes the model via the controller of one view, all other views dependent on this data should reflect the changes.&#8221; (p 127) You have, I think, pretty much implied this in your post, but here&#8217;s the additional bit&#8230; &#8220;The model therefore notifies all views whenever its data changes. The views in turn retrieve new data from the model and update the displayed information.&#8221; (p 127). So, there&#8217;s has to be a notification mechanism in place to keep everything synched up. State change must be communicated through the whole application. The book suggests that a registry be kept of all dependent components. Whenever a View is created a Controller will also be created (one duty of a View component is to create and initialize a corresponding Controller), it needs to register itself with the application, so that it can be notified when something changes.</p>
<p>One more thing. It is possible to completely separate your HTML and your JavaScript. The following chunk is from JavaScript &#8211; The Definitive Guide, 5th edition</p>
<p>&#8212; begin chunk &#8212;<br />
Unobtrusive JavaScript</p>
<p>A new client-side programming paradigm known as unobtrusive JavaScript has been gaining currency within the web development community. As its name implies, this paradigm holds that JavaScript should not draw attention to itself; it should not obtrude.[*] It should not obtrude on users viewing a web page, on content authors creating HTML markup, or on web designers creating HTML templates or CSS stylesheets.</p>
<p>[*] &#8220;Obtrude&#8221; is an obscure synonym for &#8220;intrude.&#8221; The American Heritage dictionary cites: &#8220;To impose&#8230; on others with undue insistence or without invitation.&#8221;</p>
<p>There is no specific formula for writing unobtrusive JavaScript code. However, a number of helpful practices, discussed elsewhere in this book, will put you on the right track.</p>
<p>The first goal of unobtrusive JavaScript is to keep JavaScript code separate from HTML markup. This keeps content separate from behavior in the same way that putting CSS in external stylesheets keeps content separate from presentation. To achieve this goal, you put all your JavaScript code in external files and include those files into your HTML pages with  tags (see Section 13.2.2. for details). If you are strict about the separation of content and behavior, you won&#8217;t even include JavaScript code in the event-handler attributes of your HTML files. Instead, you will write JavaScript code (in an external file) that registers event handlers on the HTML elements that need them (Chapter 17 describes how to do this).</p>
<p>As a corollary to this goal, you should strive to make your external files of JavaScript code as modular as possible using techniques described in Chapter 10. This allows you to include multiple independent modules of code into the same web page without worrying about the variables and functions of one module overwriting the variables and functions of another.</p>
<p>The second goal of unobtrusive JavaScript is that it must degrade gracefully. Your scripts should be conceived and designed as enhancements to HTML content, but that content should still be available without your JavaScript code (as will happen, for example, when a user disables JavaScript in her browser). An important technique for graceful degradation is called feature testing: before taking any actions, your JavaScript modules should first ensure that the client-side features they require are available in the browser in which the code is running. Feature testing is a compatibility technique described in more detail in Section 13.6.3.</p>
<p>A third goal of unobtrusive JavaScript is that it must not degrade the accessibility of an HTML page (and ideally it should enhance accessibility). If the inclusion of JavaScript code reduces the accessibility of web pages, that JavaScript code has obtruded on the disabled users who rely on accessible web pages. JavaScript accessibility is described in more detail in Section 13.7.</p>
<p>Other formulations of unobtrusive JavaScript may include other goals in addition to the three described here. One primary source from which to learn more about unobtrusive scripting is &#8220;The JavaScript Manifesto,&#8221; published by the DOM Scripting Task Force at <a href="http://domscripting.webstandards.org/?page_id=2" rel="nofollow">http://domscripting.webstandards.org/?page_id=2</a>.</p>
<p>&#8212; end chunk &#8212;</p>
<p>Food for thought?</p>
<p>Thanks for the post. I am currently working on a design for a very simple AJAX app and came across this when googling for &#8220;ajax model view conroller&#8221;. Attempting to answer your questions helps me get a better grasp on the MVC pattern.</p>
<p>Cheers,<br />
Ryan</p>
]]></content:encoded>
	</item>
</channel>
</rss>

