<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>/dev/null &#187; Validation</title>
	<atom:link href="http://www.nulldevice.de/tag/validation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nulldevice.de</link>
	<description>Static is evil.</description>
	<lastBuildDate>Fri, 18 Nov 2011 17:28:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Validation in the MVC design pattern</title>
		<link>http://www.nulldevice.de/2009/01/validation-in-the-mvc-design-pattern/</link>
		<comments>http://www.nulldevice.de/2009/01/validation-in-the-mvc-design-pattern/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 22:38:06 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://www.nulldevice.de/?p=975</guid>
		<description><![CDATA[Hello Martin, your article on Notification implies that validation should be done in the Model layer. There are numerous voices that see the need for validation in the Controller, as it receives user input in the first place. I argue that actually both should be done in Web applications: - First you want to make [...]]]></description>
			<content:encoded><![CDATA[<p>Hello Martin,</p>
<p>your article on Notification implies that validation should be done in<br />
the Model layer. There are numerous voices that see the need for<br />
validation in the Controller, as it receives user input in the first<br />
place. I argue that actually both should be done in Web applications:</p>
<p>- First you want to make sure that data integrity is given. You should<br />
not outsource this essential task to the Controller or the View. If<br />
integrity is not maintained by the database anyway, it MUST be done in<br />
the model. An exception is an acceptable way to respond to invalid<br />
data that is passed to the model.</p>
<p>- For usability reasons, you also want to have validation on the<br />
controller level. This however should be mainly for usability reasons,<br />
especially as the naming and number of model properties must not match<br />
form fields in every case. In a form, an email address might be split<br />
up in two input fields, whereas the model just uses one data field to<br />
store the email address. The user expects feedback on whether the<br />
username or domain part of the address are not valid. Also a modern<br />
web form should be able to list multiple validation error at one<br />
(which does not work that well when working with simple exceptions<br />
that are thrown by models).</p>
<p>In (fat client) Rich Internet Applications, you might not just access<br />
models in server-side controllers but you want to expose the model API<br />
to your client side JavaScript models (which is then a web service).<br />
If validation would be done in server-side controllers only, this<br />
would lead to a security risk or you would need to create a controller<br />
action per API function, which is basically repeated code.</p>
<p>Do you agree?</p>
<p>Merry Christmas and a happy new year,<br />
Michael Mayer</p>
<blockquote><p>Broadly yes. The domain model should be fundamentally responsible for validation, but presentations often need validation too. We need to support usability without introducing duplication.</p>
<p>For years now, I&#8217;ve been intending to capture and write about validation patterns. They are still on the horizon, although sadly distant.<br />
<span style="color: #888888;"><br />
Martin Fowler<br />
<a href="http://martinfowler.com/" target="_blank">http://martinfowler.com</a></span></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.nulldevice.de/2009/01/validation-in-the-mvc-design-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

