<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;Ak8ESXs4fyp7ImA9WhRRFE4.&quot;"><id>tag:blogger.com,1999:blog-36756501</id><updated>2011-11-27T16:06:48.537-08:00</updated><category term="Exception Exceptions  Java .NET Best Practice" /><category term="database model entity primary key development" /><category term="NHibernate XML Remember .NET" /><category term="Scrum Venture Capital Jeff Sutherland" /><title>OO Software Development</title><subtitle type="html">Take a look if you are interested in finding spike solutions to solve programmers problems. It is also a place to debate impressions and opnions.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://hcmarchezi.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>30</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/OoSoftwareDevelopment" /><feedburner:info uri="oosoftwaredevelopment" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;DU4HQ3Yzeyp7ImA9WhdXFUU.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-4742082580846265882</id><published>2011-08-28T20:18:00.000-07:00</published><updated>2011-08-28T20:18:52.883-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-28T20:18:52.883-07:00</app:edited><title>JavaScript: Object Oriented Programming</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
&lt;div style="background-color: transparent;"&gt;&lt;span id="internal-source-marker_0.10210037208162248" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;By using functions and the structures above it is possible to a function object which syntax works just like a C++/Java class. See examples below.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span id="internal-source-marker_0.10210037208162248" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 19px; font-weight: bold; white-space: pre-wrap;"&gt;Classes&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;In JavaScript classes are declared as functions.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;function&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; Task(name,dueDate)&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.name = name;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.dueDate = dueDate;&lt;br class="kix-line-break" /&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;var myTask = new Task(“Clean house”,”2011-07-01”);&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;myTask.name = “some new name”;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 19px; font-weight: bold; white-space: pre-wrap;"&gt;Methods&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: 19px; font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; font-weight: normal; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: 19px; font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; font-weight: normal; white-space: pre-wrap;"&gt;Methods are declared by extending the function prototype.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New';"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;var User = &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 15px; white-space: pre-wrap;"&gt;function(email,password) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.email = “”; // public field&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.password = “”;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;User.prototype.generatePassword = function() { &amp;nbsp;// public method&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.password = "generatedpass";&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;var user = new User(“you@email.com”,”mypassword”);&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;user.generatePassword(); // password is generatedpass&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Alternatively methods can be declared inside the function declaration.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;var User = function(email,password) {&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.email = “”;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.password = “”;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.generatePassword = function() { &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.password = “generatedpass”;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;};&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 19px; font-weight: bold; white-space: pre-wrap;"&gt;Inheritance&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;In order to make a class inherit from another class, the subclass prototype must be set to the desired parent object. It is also necessary to set the constructor as the current class which is a little od. See example below.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;function Person() {&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.firstname = "James";&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Person.prototype.generateName = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.firstname = "generatedname";&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;function Student() {&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.school = "Rahway School";&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Student.prototype = new Person();&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Student.prototype.constructor = Student;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Student.prototype.setBestSchool = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;this.school = "Best school in town";&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;};&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 19px; font-weight: bold; white-space: pre-wrap;"&gt;Polymorphism&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;Polymorphism can be achieved by simply declaring methods with the same name.&lt;/span&gt;&lt;/div&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Consider the hierarchy of figures as an example below.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;function Photo() { &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Photo.prototype.getDestinationPath = function() { &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;return “./photos/common”;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;function PartyPhoto() {&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;PartyPhoto.prototype = new Photo();&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;PartyPhoto.prototype.constructor = PartyPhoto;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;PartyPhoto.prototype.getDestinationPath = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;return “./photos/parties”;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;photo = new Photo();&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;photo.getDestinationPath(); // path for common photos&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;partyPhoto = new PartyPhoto();&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;partyPhoto.getDestinationPath(); // path for party photos&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 19px; font-weight: bold; white-space: pre-wrap;"&gt;Encapsulation&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;div&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;In the examples above all attributes and methods were public. In order to declare private attributes or methods one solution is to follow the template code below: (taken from &lt;/span&gt;&lt;a href="http://www.codeproject.com/KB/scripting/jsoops.aspx"&gt;&lt;span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;"&gt;http://www.codeproject.com/KB/scripting/jsoops.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; )&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;function MyClass(){ &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;//Private members&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;return{&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Public members&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: italic; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;An App class can be implemented as:&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;function App(appname,description) {&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var _name = appname;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var _description = description&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;return {&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;getName: function() { return _name; },&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;getDescription: function() { return _description; },&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;setName: function(appname) { _name = appname; },&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;setDescription: function(description) { _description = description; }&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;var myApp = new App(“voila”,”my game”);&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;var.setName(“other game”);&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New';"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Please note that this approach does not offer a way to have encapsulation and inheritance at the same time. Read next section to know one way to achieve this.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 19px; font-weight: bold; white-space: pre-wrap;"&gt;Inheritance with Encapsulation&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;&lt;div style="background-color: transparent;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial; font-size: 15px; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;By experimenting with the approach above, I found out a different way that made it possible to have both encapsulation and inheritance in JavaScript. &lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;The idea is to declare private members as function variables as above and then augment the parent object with the desired public functions. Thus it is not necessary to work with prototypes.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Take the generic Person class as an example:&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;function Person(name) {&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;// Private Members&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var _name = "";&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;// Public Members (accesses private members)&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var obj = new Object();&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;obj.setName = function(name) { _name = name; };&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;obj.getName = function() { return _name; &amp;nbsp;}; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;// Constructor&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;obj.setName(name);&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;return obj;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;A person instance will have access to getName and SetName but not _name attribute and therefore we have encapsulation.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;For a Student class that inherits from Person, the code would be:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 15px; white-space: pre-wrap;"&gt;function Student(name,school) {&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;// Private Members&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var _school = "";&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;// Creating parent object: Studen inherits from Person&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var parent = new Person(name);&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;// Augmenting parent object with Student methods&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;parent.setSchool = function(school) { _school = school; };&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;parent.getSchool = function() { return _school; };&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;// Constructor Logic (Initialization)&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;parent.setSchool(school);&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;return parent;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;These functions can be used just like normal classes:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 15px; white-space: pre-wrap;"&gt;var person = new Person("James");&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;person._name; // undefined&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;person.getName(); // James&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;var student = new Student("Jack","Orange City School");&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;student._name; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// undefined&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;student.getName(); &amp;nbsp;// Jack&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;student._school; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// undefined&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;student.getSchool(); // Orange City School&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-4742082580846265882?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3XrFSolkQIWwDAtAFb0wtQUrEM8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3XrFSolkQIWwDAtAFb0wtQUrEM8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3XrFSolkQIWwDAtAFb0wtQUrEM8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3XrFSolkQIWwDAtAFb0wtQUrEM8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/fKr7LXA3TRA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/4742082580846265882/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=4742082580846265882" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/4742082580846265882?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/4742082580846265882?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/fKr7LXA3TRA/javascript-object-oriented-programming.html" title="JavaScript: Object Oriented Programming" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2011/08/javascript-object-oriented-programming.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUAMQn05cSp7ImA9Wx9bGEg.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-6444516802475935421</id><published>2011-02-27T12:40:00.000-08:00</published><updated>2011-02-27T17:49:43.329-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-27T17:49:43.329-08:00</app:edited><title>iPhone Development: to Objective-C or not to Objective-C ?</title><content type="html">When I think of Objective-C, what comes to my mind is a niche programming language for the MacOS and Apple related products. Thus as far as I know this is the only officially supported language to develop products for iPhones, iPods, iPads and so on ....&lt;br /&gt;
On the other hand I really what to develop apps that will work in Windows, Linux and MacOS, and for this purpose I see two options:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1) Develop in C/C++ and try to find tools that translate this code to Objective-C and/or MacOS&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2) Use Objective-C to develop any kind of application (at least desktop and mobile apps)&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Developing portable iPhone apps outside Objective-C&lt;/h2&gt;&lt;br /&gt;
&lt;h3&gt;Swig&lt;/h3&gt;For the first option, there is swig ( http://www.swig.org/ ) which is a wrapper for C++ to export its classes and/or functions to several languages (Objective-C is a work in progress).&lt;br /&gt;
However it doesn´t really solve the problem because there are libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Mono Touch&lt;/h3&gt;The Mono Touch ( http://monotouch.net/ ) is probably one of the most interesting project to develop apps for the iPhone without Objective-C. It makes it possible to develop apps with C#.NET. The same Mono project also make it possible to develop apps for Linux. As a consequence, C#.NET could be seriously considered to develop apps for a wide range of platforms. However unlike Mono one must pay to start using it which may not be a problem if you are familiarized with C#.NET.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;PhoneGap&lt;/h3&gt;Another options is PhoneGap ( http://www.phonegap.com ) which is an open-source framework whose objective is to let developers to write apps with HTML5+CSS+JavaScript and execute it to the different mobile platforms including iOS. &lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Objective-C as a portable programming language&lt;/h2&gt;&lt;br /&gt;
I recently read about he mechanics and philosophy of Objective-C language and I got quite impressed by its features. It is not just C with classes as I heard before, it is actually a powerful dynamic language. Everything is an object including the classes itself what reminds me of Smalltalk, LISP and Python.&lt;br /&gt;
&lt;br /&gt;
There are also some options to use Objective-C outside of the Apple ecosystem:&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;GNU Step&lt;/h3&gt;As stated in their website ( http://www.gnustep.org/ ) the objective is to create an open version of Cocoa (former NextStep) for several platforms including Linux and Windows.&lt;br /&gt;
&lt;br /&gt;
Besides porting the API this project also comes with several developer tools such as an IDE named &lt;b&gt;ProjectCenter&lt;/b&gt; and a GUI code generator called &lt;b&gt;Gorm&lt;/b&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-6444516802475935421?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/d5n_IcgQkpEh6XsoLMenIkG-pqs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d5n_IcgQkpEh6XsoLMenIkG-pqs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/d5n_IcgQkpEh6XsoLMenIkG-pqs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d5n_IcgQkpEh6XsoLMenIkG-pqs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/-wV6uUgl3AE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/6444516802475935421/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=6444516802475935421" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/6444516802475935421?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/6444516802475935421?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/-wV6uUgl3AE/iphone-developtment-to-objective-c-or.html" title="iPhone Development: to Objective-C or not to Objective-C ?" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2011/02/iphone-developtment-to-objective-c-or.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUQMRX8_eip7ImA9Wx9bGE8.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-5204040479067409846</id><published>2011-02-27T09:23:00.000-08:00</published><updated>2011-02-27T09:23:04.142-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-27T09:23:04.142-08:00</app:edited><title>Publishing ClickOnce winforms applications with command-line MSBuild</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;One of the most interesting characteristics of tools such as CCNet and Nant is the automated deploy.&lt;br /&gt;
&lt;br /&gt;
I found many examples of how to publish an application with pre-configured projects with click-one but I wanted to do it different. &lt;br /&gt;
&lt;br /&gt;
In order to make the project file cleaner the approach was to remove all click-once configurations from the project(*.csproj) so that command-line MSBuild will take care of publication configuration in a NAnt script.&lt;br /&gt;
&lt;br /&gt;
After some full-days of research, I found the solution below. I hope it helps in your project.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:html"&gt;&lt;exec program="${dotnetFrameworkDir}\MSBuild.exe"&gt;
  &lt;arg value="${basePath}\MyProject\MyProject.csproj"&gt;&lt;/arg&gt;
  &lt;arg value="/target:publish"&gt;&lt;/arg&gt;
  &lt;arg value="/p:IsWebBootstrapper=true"&gt;&lt;/arg&gt;
  &lt;arg value="/p:SignManifests=true"&gt;&lt;/arg&gt;
  &lt;arg value="/p:ManifestKeyFile=${basePath}\MyProject\MyCertificate.pfx"&gt;&lt;/arg&gt;
  &lt;arg value="/p:TargetZone=LocalIntranet"&gt;&lt;/arg&gt;
  &lt;arg value="/p:GenerateManifests=true"&gt;&lt;/arg&gt;
  &lt;arg value="/p:PublishUrl=${clickOnceDir}"&gt;&lt;/arg&gt;
  &lt;arg value="/p:Install=true"&gt;&lt;/arg&gt;
  &lt;arg value="/p:InstallFrom=Web"&gt;&lt;/arg&gt;
  &lt;arg value="/p:UpdateEnabled=true"&gt;&lt;/arg&gt;
  &lt;arg value="/p:UpdateRequired=true"&gt;&lt;/arg&gt;
  &lt;arg value="/p:InstallUrl=http://myPublishUrlAddress"&gt;&lt;/arg&gt;
  &lt;arg value="/p:TargetCulture=pt-BR"&gt;&lt;/arg&gt;
  &lt;arg value="/p:ProductName=MyProject"&gt;&lt;/arg&gt;
  &lt;arg value="/p:PublisherName=MyCompany"&gt;&lt;/arg&gt;
  &lt;arg value="/p:MinimumRequiredVersion=${CCNetLabel}"&gt;&lt;/arg&gt;
  &lt;arg value="/p:CreateWebPageOnPublish=true"&gt;&lt;/arg&gt;
  &lt;arg value="/p:WebPage=${webPage}"&gt;&lt;/arg&gt;
  &lt;arg value="/p:OpenBrowserOnPublish=false"&gt;&lt;/arg&gt;
  &lt;arg value="/p:ApplicationRevision=17"&gt;&lt;/arg&gt;
  &lt;arg value="/p:ApplicationVersion=${CCNetLabel}"&gt;&lt;/arg&gt;

  &lt;arg value="/p:CreateDesktopShortcut=true"&gt;&lt;/arg&gt;
  &lt;arg value="/p:PublishWizardCompleted=true"&gt;&lt;/arg&gt;
  &lt;arg value="/p:BootstrapperComponentsLocation=Absolute"&gt;&lt;/arg&gt;
  &lt;arg value="/p:BootstrapperComponentsUrl=${bootstrapperUrl}"&gt;&lt;/arg&gt;

  &lt;arg value="/p:GenerateBootstrapperSdkPath=${pathBootStrapper}"&gt;&lt;/arg&gt;
  &lt;arg value="/p:UpdateUrlEnabled=false"&gt;&lt;/arg&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-5204040479067409846?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Ev05GrqkD7juBc_1EB4m-2Oc1wU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ev05GrqkD7juBc_1EB4m-2Oc1wU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Ev05GrqkD7juBc_1EB4m-2Oc1wU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ev05GrqkD7juBc_1EB4m-2Oc1wU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/Hgg9-cmM2W4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/5204040479067409846/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=5204040479067409846" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/5204040479067409846?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/5204040479067409846?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/Hgg9-cmM2W4/publishing-clickonce-winforms.html" title="Publishing ClickOnce winforms applications with command-line MSBuild" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2011/02/publishing-clickonce-winforms.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0cHSX07eCp7ImA9WxFWFUQ.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-1231348666562030155</id><published>2010-06-03T11:50:00.000-07:00</published><updated>2010-06-03T11:50:38.300-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-06-03T11:50:38.300-07:00</app:edited><title>Tools and Utilities for the .NET Developer</title><content type="html">Here is a list I got from the internet that might be useful (at least for a while):&lt;br /&gt;
&lt;br /&gt;
http://geekswithblogs.net/mbcrump/archive/2010/05/25/tools-and-utilities-for-the-.net-developer.aspx&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-1231348666562030155?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/gfSlAeCT-yg3xklWdovI_mTvvR8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gfSlAeCT-yg3xklWdovI_mTvvR8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/gfSlAeCT-yg3xklWdovI_mTvvR8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gfSlAeCT-yg3xklWdovI_mTvvR8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/dpGgHB40E8o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/1231348666562030155/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=1231348666562030155" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/1231348666562030155?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/1231348666562030155?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/dpGgHB40E8o/tools-and-utilities-for-net-developer.html" title="Tools and Utilities for the .NET Developer" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2010/06/tools-and-utilities-for-net-developer.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU4GQHk7fSp7ImA9WxFQFEg.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-4559241205275067502</id><published>2010-05-09T19:08:00.000-07:00</published><updated>2010-05-09T19:18:41.705-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-09T19:18:41.705-07:00</app:edited><title>Using Fluent Builder Pattern to Configure Test Objects</title><content type="html">Depending on the complexity of the domain model, configuring mock objects for specific cenarios can make the resulting test code to get messy.  &lt;br /&gt;
&lt;br /&gt;
Consider the situation below with C#, NUnit and Moq framework&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;[Test]
[ExpectedException(InvalidPaymentAgreementException)]
public void PaymentAgreementMustNotBeCreatedWhenThePaymentOptionIsNotValidForTheDebtType()
{
  Mock &amp;lt PaymentOption &amp;gt somePaymentOptionMock = new Mock &amp;lt Paymentoption &amp;gt ();

  Mock &amp;lt DebtType &amp;gt debTypeMock = new Mock &amp;lt DebtType &amp;gt ();
  debtTypeMock
    .Setup(debtType.GetPaymentOptions())
    .Returns(new List &amp;lt PaymentOption &amp;gt (){somePaymentOptionMock.Object});

  Mock &amp;lt PaymentOption &amp;gt anotherPaymentOptionMock = new Mock &amp;lt PaymentOption &amp;gt ();

  Mock &amp;lt Debt &amp;gt debtMock = new Mock &amp;lt Debt &amp;gt ();
  debtMock.Setup(debt.DebtType).Returns(debTypeMock.Object);            

  PaymentAgreement paymentAgreement = new PaymentAgreement(
    new PaymentAgreementCreationParameter()
    {
      AgreementYear = SystemDate.Get().Value.Year,
      AgreementNumber = 1,
      AgreementCreationDate = SystemDate.Get().Value.Date,
      NumberOfInstallments = 1,
      AgreementValue = 100.0m,
      Debts = new List &amp;lt Debt &amp;gt () { debtMock.Object },
      SelectedPaymentOption =  anotherPaymentOptionMock.Object
    });
}
&lt;/pre&gt;&lt;br /&gt;
A developer who reads the unit test can take a consirable amount of time to understand what is actually being tested even if a well-designed mock framework such as Moq is in use. Most of this work is about configuring mock objects. Besides the code size, the unit test doesn´t speak the language of the domain (business) and thus it becomes a mass of meaningless mock configuration. &lt;br /&gt;
I am on my way to learn how to apply TDD effectvely in software development and I quickly realized that the quality of unit tests are very important in order to this kind of methodology to succeed. &lt;br /&gt;
&lt;br /&gt;
Accidentally some days I read an interesting post from Andrian about Rich Domain Tests at http://adrianhummel.wordpress.com/ and I decided to apply his idea.&lt;br /&gt;
After reading his post I got to the conclusion that one way to solve or at least minimize this unit-test-messy-code-problem was by using a fluent builder pattern to configure mock objects by using a builder whose interface could be describe how I am configuring a mock object with an interface closer to domain language.&lt;br /&gt;
&lt;br /&gt;
The unit test below is a rewritten from the example above with the concepts described here:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;[Test]
[ExpectedException(InvalidPaymentAgreementException)]
public void PaymentAgreementMustNotBeCreatedWhenThePaymentOptionIsNotValidForTheDebtType()
{
  PaymentOption somePaymentOption = PaymentOptionMockBuilder
                                    .Begin()
                                    .BuildPaymentOption();

  DebtType debtType = DebtTypeMockBuilder
                      .Begin()  
                      .AddPaymentOptionOf(somePaymentOption)
                      .BuildDebtType();
            
  PaymentOption anotherPaymentOption = PaymentOptionMockBuilder
                                       .Begin()
                                       .BuildPaymentOption();          
            
  Debt debt = DebtMockBuilder
              .Begin()
              .WithDebtTypeOf(debtType)
              .BuildDebt();

  PaymentAgreement paymentAgreement = new PaymentAgreement(
    new PaymentAgreementCreationParameter()
    {
      AgreementYear = SystemDate.Get().Value.Year,
      AgreementNumber = 1,
      AgreementCreationDate = SystemDate.Get().Value.Date,
      NumberOfInstallments = 1,
      AgreementValue = 100.0m,
      Debts = new List &amp;lt Debt &amp;gt () { debt},
      SelectedPaymentOption =  anotherPaymentOption
    });

}
&lt;/pre&gt;&lt;br /&gt;
The fluent builder for Debt is DebtMockBuilder and can be programmed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;public class DebtMockBuilder
    {
        private Mock &amp;lt Debt &amp;gt _debtMock;

        public static DebtMockBuilder Begin()
        {
            DebtMockBuilder builder = new DebtMockBuilder();
            builder._ debtMock = new Mock &amp;lt Debt &amp;gt ();
            return builder;
        }

        public Debt BuildDebt()
        {
            return _debtMock .Object;
        }

        public DebtMockBuilder WithDebtTypeOf(DebtType debtType)
        {
            this._debtMock.Setup(debt =&amp;gt; debt.DebtType).Returns(debtType);
            return this;
        }
    }
&lt;/pre&gt;&lt;br /&gt;
PaymentOptionMockBuilder follows the same idea.&lt;br /&gt;
&lt;br /&gt;
Although I see that some improvements are needed I could see the following advantages from fluent mock builders:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;The test code was easier to understand because domain terms were applied instead of specific API language.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Specific mock framework calls were encapsulated which theoretically can let programmers to use another mock framework in other projects or using more than one mock framework in the same test (I dont know why someone would do such a thing...).&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Finally mock configuration becomes more flexible since existing methods don´t have to be modified to include new configuration but only a new configuration method is needed. Thus mock configuration can evolve as needed without loosing the domain interface.&lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-4559241205275067502?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Sb7SSX1pf7BteoGCeBc7I0gEuoI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Sb7SSX1pf7BteoGCeBc7I0gEuoI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Sb7SSX1pf7BteoGCeBc7I0gEuoI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Sb7SSX1pf7BteoGCeBc7I0gEuoI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/BPUPvelf6Bs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/4559241205275067502/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=4559241205275067502" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/4559241205275067502?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/4559241205275067502?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/BPUPvelf6Bs/using-fluent-builder-pattern-to.html" title="Using Fluent Builder Pattern to Configure Test Objects" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2010/05/using-fluent-builder-pattern-to.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0MCSHo_cSp7ImA9WxFQE0g.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-7805844662808811783</id><published>2010-05-08T15:54:00.000-07:00</published><updated>2010-05-08T15:57:49.449-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-08T15:57:49.449-07:00</app:edited><title>Test-Driven-Development Best Practices</title><content type="html">&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;I recently read a very intersting conversation in StackOverflow.com about test-driven development.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;I found it very instersting and the principles can be summarized as follows: (not ordered by importance)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;b&gt;1. &lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Write the test first, then the code.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;Reason: This ensures that you write testable code and that every line of code gets tests written for it.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;b&gt;2. &lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Design classes using dependency injection.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;Reason: You cannot mock or test what cannot be seen.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;b&gt;3. &lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Separate UI code from its behavior using Model-View-Controller or Model-View-Presenter.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;Reason: Allows the business logic to be tested while the parts that can't be tested (the UI) is minimized.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;b&gt;4. &lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Do not write static methods or classes.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;Reason: Static methods are difficult or impossible to isolate and Rhino Mocks is unable to mock them.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;b&gt;5. &lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Program off interfaces, not classes.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;Reason: Using interfaces clarifies the relationships between objects. An interface should define a service that an object needs from its environment. Also, interfaces can be easily mocked using Rhino Mocks and other mocking frameworks.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;b&gt;6. &lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Isolate external dependencies.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;Reason: Unresolved external dependencies cannot be tested.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;b&gt;7. &lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Mark as virtual the methods you intend to mock.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;Reason: Rhino Mocks is unable to mock non-virtual methods.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;8. Use creational design patterns.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;This will assist with DI, but it also allows you to isolate that code and test it independently of other logic.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;9. Write tests using&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;a href="http://weblogs.java.net/blog/wwake/archive/2003/12/tools_especiall.html" style="color: #114170;" target="_blank"&gt;&lt;span style="color: blue;"&gt;&lt;b&gt;&lt;u&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Bill Wake's Arrange/Act/Assert technique&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;This technique makes it very clear what configuration is necessary, what is actually being tested, and what is expected.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;10. Don't be afraid to roll your own mocks/stubs.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;Often, you'll find that using mock object frameworks makes your tests incredibly hard to read. By rolling your own, you'll have complete control over your mocks/stubs, and you'll be able to keep your tests readable. (Refer back to previous point.)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;11. Avoid the temptation to refactor duplication out of your unit tests into abstract base classes, or setup/teardown methods.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;Doing so hides configuration/clean-up code from the developer trying to grok the unit test. In this case, the clarity of each individual test is more important than refactoring out duplication.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;12. Implement Continuous Integration.&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;Check-in your code on every "green bar." Build your software and run your full suite of unit tests on every check-in. (Sure, this isn't a coding practice, per se; but it is an incredible tool for keeping your software clean and fully integrated.)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt; &lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Reference:&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="http://stackoverflow.com/questions/124210/best-practices-of-test-driven-development-using-c-and-rhinomocks" style="color: #114170;" target="_blank"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;http://stackoverflow.com/&lt;wbr&gt;&lt;/wbr&gt;questions/124210/best-&lt;wbr&gt;&lt;/wbr&gt;practices-of-test-driven-&lt;wbr&gt;&lt;/wbr&gt;development-using-c-and-&lt;wbr&gt;&lt;/wbr&gt;rhinomocks&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-7805844662808811783?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0-S990hBZPUs3M2T1E_Bio9CbCY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0-S990hBZPUs3M2T1E_Bio9CbCY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0-S990hBZPUs3M2T1E_Bio9CbCY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0-S990hBZPUs3M2T1E_Bio9CbCY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/UqP1MiNkVBE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/7805844662808811783/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=7805844662808811783" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/7805844662808811783?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/7805844662808811783?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/UqP1MiNkVBE/test-driven-development-best-practices.html" title="Test-Driven-Development Best Practices" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2010/05/test-driven-development-best-practices.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8HQnwycCp7ImA9WxFTEUo.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-8509143538553537895</id><published>2010-02-24T17:38:00.000-08:00</published><updated>2010-04-01T19:03:53.298-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-01T19:03:53.298-07:00</app:edited><title>Name Convention for Object Oriented Apps</title><content type="html">&lt;span class="Apple-style-span" style="font-family: Georgia; font-size: 13px;"&gt;Some time ago I came across with a question about naming conventions for different parts of the software: UI, Service, Entities, etc. I decided to share some of the conventions I have been using.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Georgia; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Georgia; font-size: 13px;"&gt;&lt;u&gt;&lt;b&gt;Naming Convention: ( Most used ):&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;nbsp;&lt;b&gt;Entities&lt;/b&gt;: As it is part of the domain package, no prefixes or suffixes here:&amp;nbsp;&lt;u&gt;Ex:&lt;/u&gt;&amp;nbsp;Car, Client, etc.&lt;br /&gt;
&lt;br /&gt;
-&amp;nbsp;&lt;b&gt;Repository&lt;/b&gt;: Usually a suffix &lt;class&gt;Repository.&amp;nbsp;&lt;u&gt;Ex:&lt;/u&gt;&amp;nbsp;ClientRepository, CarRepository, etc.&lt;br /&gt;
&lt;br /&gt;
-&amp;nbsp;&lt;b&gt;ValueObject&lt;/b&gt;: Value objects are part of the domain so it follows entity´s convention.&amp;nbsp;&lt;u&gt;Ex:&lt;/u&gt;&amp;nbsp;Money, Address, etc.&lt;br /&gt;
&lt;br /&gt;
-&amp;nbsp;&lt;b&gt;DTO&lt;/b&gt;: Usually a suffix &lt;class&gt;DTO.&amp;nbsp;&lt;u&gt;Ex:&lt;/u&gt;&amp;nbsp;ClientRegistrationDTO, CarRentDTO, AddressDTO, etc.&lt;br /&gt;
&lt;br /&gt;
-&amp;nbsp;&lt;b&gt;Service&lt;/b&gt;: Usually a suffix &lt;class&gt;Service.&amp;nbsp;&lt;u&gt;Ex:&lt;/u&gt;&amp;nbsp;ClientRegistrationService, CarRentService, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Namespace Convention:&lt;/b&gt;&lt;/u&gt;&amp;nbsp;(My Suggestion)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Entities,&amp;nbsp;&lt;/b&gt;&lt;b&gt;ValueObjects, Repositories Interfaces, Domain Services&lt;/b&gt;&amp;nbsp;&lt;b&gt;(Domain Layer)&lt;/b&gt;&lt;br /&gt;
&lt;my company=""&gt;.&lt;my domain=""&gt;.Domain.&lt;my class=""&gt;&lt;br /&gt;
&lt;u&gt;Ex:&lt;/u&gt;&amp;nbsp;Acme.Finantial.Domain.Debt,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Acme.HR.Domain.CheckOvertimeService,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Acme.Core.Domain.IPersonRepository &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Application Services&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;my company=""&gt;.&lt;my domain=""&gt;.Service.&lt;my class=""&gt;&lt;br /&gt;
&lt;u&gt;Ex:&lt;/u&gt;&amp;nbsp;Acme.Sales.Service.ClientRegistrationService&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Presentation Layer&lt;/b&gt;&lt;br /&gt;
&lt;my company=""&gt;.&lt;my domain=""&gt;.Presentation.&lt;my class=""&gt;&lt;br /&gt;
Ex: Acme.HR.Presentation.IClientRegistrationView, Acme.HR.Presentation.WebClientRegistration&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Persistence Layer&lt;/b&gt;&lt;br /&gt;
&lt;my company=""&gt;.&lt;my domain=""&gt;.Persistence.&lt;my class=""&gt;&lt;br /&gt;
Ex: Acme.Core.Persistence.PersonRepositoryImpl (&amp;lt;--- implementation in NH, for example)&lt;/my&gt;&lt;/my&gt;&lt;/my&gt;&lt;/my&gt;&lt;/my&gt;&lt;/my&gt;&lt;/my&gt;&lt;/my&gt;&lt;/my&gt;&lt;/my&gt;&lt;/my&gt;&lt;/my&gt;&lt;/class&gt;&lt;/class&gt;&lt;/class&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-8509143538553537895?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/SMIDcsdRzza9AE6IWVR435UL3GE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SMIDcsdRzza9AE6IWVR435UL3GE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/SMIDcsdRzza9AE6IWVR435UL3GE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SMIDcsdRzza9AE6IWVR435UL3GE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/oSQ-zxiD3y0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/8509143538553537895/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=8509143538553537895" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/8509143538553537895?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/8509143538553537895?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/oSQ-zxiD3y0/name-convention-for-object-oriented.html" title="Name Convention for Object Oriented Apps" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2010/02/name-convention-for-object-oriented.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEEGRHg5eCp7ImA9WxBVGEU.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-4151743441454581906</id><published>2010-02-22T16:16:00.000-08:00</published><updated>2010-02-22T16:57:05.620-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-22T16:57:05.620-08:00</app:edited><title>Unit Testing Linq Queries in Moq</title><content type="html">After some google research and experimentation I found that it was not worth to mock methods that return IQueryable or IQueryable&lt;t&gt; because in order to use it programmers have to make use of extension methods. And this kind of methods are not supported by Moq ( a minimalistic mock framework ).&lt;br /&gt;&lt;br /&gt;This is the DAO interface I want to test.&lt;br /&gt;&lt;/t&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;public interface IDAOFactory&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;     public abstract IQueryable &amp;lt T &amp;gt Query &amp;lt T &amp;gt ();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is the moq unit test that fails, since I can´t use Linq directly.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;[Test]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;public void LinqQueryTest()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;// This moq configuration will trigger an exception – Can´t make use of extension methods&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;     daoFactoryMock.Setup(d =&gt; (from o in d.Query &amp;lt Order &amp;gt ()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;                                where o.Id &gt;= 0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;                                select o.Id).ToList())&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;                   .Returns( new List &amp;lt long &amp;gt () { 1, 2 } );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;It turns out that the solution is easily solved by using a collection as a data source.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;[Test]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;public void LinqQueryTest()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    // Creates a IQueryable&lt;/span&gt;&lt;/span&gt;&lt;order  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt; from a Collection&lt;br /&gt;   IList &amp;lt Order &amp;gt lstOrders = new List &amp;lt Order &amp;gt ()&lt;br /&gt;   { orderMock1.Object, orderMock2.Object, orderMock3.Object };&lt;br /&gt;   IQueryable &amp;lt Order &amp;gt orderQuery = lstOrders.AsQueryable &amp;lt Order &amp;gt ();&lt;br /&gt;&lt;br /&gt;   // Configures the Query &amp;lt Order &amp;gt to return IQueryable &amp;lt Order &amp;gt implementation&lt;br /&gt;   daoFactoryMock.Setup(d =&gt; d.Query &lt;&gt; ()).Returns(orderQuery);&lt;br /&gt;&lt;br /&gt;   // Now the linq queries can be used naturally   &lt;br /&gt;   IList &amp;lt Order &amp;gt lstResult =  (from o in daoFactoryMock.Object.Query &amp;lt Order &amp;gt ()&lt;br /&gt;                                where o.Id &gt;= 0&lt;br /&gt;                                Select o).ToList();&lt;br /&gt;&lt;br /&gt;   // Checking output results&lt;br /&gt;   Assert.AreEqual(3, lstResult.Count);&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/order&gt;&lt;br /&gt;It is important to notice that the collection elements that should also be mock objects must contain all the necessary data in order to make the correct test.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-4151743441454581906?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/m83N8yWwOSoHDFALmfslhcZBBKU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/m83N8yWwOSoHDFALmfslhcZBBKU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/m83N8yWwOSoHDFALmfslhcZBBKU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/m83N8yWwOSoHDFALmfslhcZBBKU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/IveLh81hAdg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/4151743441454581906/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=4151743441454581906" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/4151743441454581906?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/4151743441454581906?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/IveLh81hAdg/unit-testing-linq-queries-in-moq.html" title="Unit Testing Linq Queries in Moq" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2010/02/unit-testing-linq-queries-in-moq.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEYMSHYzeSp7ImA9WxFQFEg.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-2062802732618331107</id><published>2009-12-26T10:56:00.000-08:00</published><updated>2010-05-09T18:49:49.881-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-09T18:49:49.881-07:00</app:edited><title>Model View Controller with Events in .NET</title><content type="html">&lt;div&gt;This is often a confused design pattern and its main purpose is to separate objects that assume different roles in a software.&lt;br /&gt;
These roles are:&lt;/div&gt;&lt;ul&gt;&lt;li&gt;models - objects that actual execute the system tasks&lt;/li&gt;
&lt;li&gt;views - objects that display the system data&lt;/li&gt;
&lt;li&gt;controllers - objects that capture the user intentions from the view and route to the right actions&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;Usually Views have a reference to the controller however another approach below shows how to decouple the views from the controllers.&lt;br /&gt;
Views can be implemented in several ways depending on the UI library. For that reason, views are better represented as interfaces. However in order to reduce coupling between views and controllers, &lt;span style="font-weight: bold;"&gt;events &lt;/span&gt;can be used in the interface views.&lt;/div&gt;The example below shows a client registration view:&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;using System;
namespace MyController
{
  public interface IClientRegistrationView
  {
    public long Id { get; set; }
    public string Name { get; set; }
    public string Registration { get; set; }
    public event ClientEventHandler InsertRequested;
    public event ClientEventHandler UpdateRequested;
    public event ObjectIdEventHandler &amp;lt long &amp;gt RemoveRequested;
    public event ObjectIdEventHandler &amp;lt long &amp;gt RetrieveRequested;
  }
}
&lt;/pre&gt;Specific event arguments were also created for the Client Registration View:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;ClientEventArgs &lt;/span&gt;- contains client fields so that it can be sent to the underlying layer.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-weight: bold;"&gt;ObjectIdEventArgs &lt;/span&gt;- contains a generic object id for deletion and queries purposes.&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div&gt;See event argument classes below:&lt;/div&gt;&lt;br /&gt;
&lt;pre class="brush:csharp" name="code"&gt;using System;
namespace MyController
{
  public delegate void ClientEventHandler(object sender, ClientEventArgs e);
  public class ClientEventArgs : EventArgs
  {
  public long Id { get; set; }
  public string Name { get; set; }
  public string Registration { get; set; }
  }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="brush:csharp" name="code"&gt;using System;
namespace MyController
{
  public delegate void ObjectIdEventHandler &amp;lt T &amp;gt (object sender, ObjectIdEventArgs &amp;lt T &amp;gt e);
  public class ObjectIdEventArgs &amp;lt T &amp;gt : EventArgs
  {
    public T Id { get; set; }
  }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
The controller will have a reference to a view (an interface) and it will access the view´s data fields for the client which is Id, Name and Registration.&lt;br /&gt;
Besides that, the controller will also be told to trigger actions by listening to the view´s events.&lt;br /&gt;
In this example, the service acts as if it was the model of the system.&lt;/div&gt;&lt;br /&gt;
&lt;pre class="brush:csharp" name="code"&gt;using System;
using MyService;
namespace MyController
{
  public class ClientRegistrationController
  {
    private IClientRegistrationView View { get; set; }
    private ClientRegistrationService Service { get; set; }
    public ClientRegistrationController(IClientRegistrationView view)
    {
      View = view;
      View.InsertRequested += new ClientEventHandler(View_InsertRequested);
      View.UpdateRequested += new ClientEventHandler(View_UpdateRequested);
      View.RemoveRequested += new ObjectIdEventHandler &amp;lt long &amp;gt (View_RemoveRequested);
      View.RetrieveRequested += new ObjectIdEventHandler &amp;lt long &amp;gt (View_RetrieveRequested);
      Service = new ClientRegistrationService();   
    }
    void View_InsertRequested(object sender, ClientEventArgs e)
    {
      ClientDTO dto = new ClientDTO() { Id = e.Id, Name = e.Name, Registration = e.Registration };
      Service.Insert(dto);
      this.View.Id = dto.Id;
    }
    void View_UpdateRequested(object sender, ClientEventArgs e)
    {
      Service.Update(new ClientDTO() { Id = e.Id, Name = e.Name, Registration = e.Registration });
    }
    void View_RemoveRequested(object sender, ObjectIdEventArgs &amp;lt long &amp;gt e)
    {
      Service.Remove(e.Id);
    }
    void View_RetrieveRequested(object sender, ObjectIdEventArgs &amp;lt long &amp;gt e)
    {
      ClientDTO dto = Service.Retrieve(e.Id);
      this.View.Id = dto.Id;
      this.View.Name = dto.Name;
      this.View.Registration = dto.Registration;
    }
  }
}
&lt;/pre&gt;As it can be seen above, the View doesn´t need to have a reference to the Controller. The view is totally decoupled form the controller but it can communicate with it by listening to the events.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-2062802732618331107?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PTq47Lse_vFsKeCjXV7BvNJKMVw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PTq47Lse_vFsKeCjXV7BvNJKMVw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PTq47Lse_vFsKeCjXV7BvNJKMVw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PTq47Lse_vFsKeCjXV7BvNJKMVw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/XQZWo8ucTTE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/2062802732618331107/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=2062802732618331107" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/2062802732618331107?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/2062802732618331107?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/XQZWo8ucTTE/model-view-controller-with-events-in.html" title="Model View Controller with Events in .NET" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2009/12/model-view-controller-with-events-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkcBQH89eSp7ImA9WxNXEEQ.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-2019315421038352809</id><published>2009-09-27T15:04:00.000-07:00</published><updated>2009-09-27T15:20:51.161-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-27T15:20:51.161-07:00</app:edited><title>Extreme Programming Impressions</title><content type="html">Whe I first read about XP Programming in 2002 ( http://www.extremeprogramming.org/ ) which is one of the agile methodologies for software development I didn't take it seriously.&lt;br /&gt;At that time the authors of this methodology were saying that software didn´t need to be documented, models were not necessary or useful at all, people should be the documentation of the software, etc.&lt;br /&gt;Immediately it came to my mind that it couldn´t work for many small (and big) software companies due to several problems:&lt;br /&gt;&lt;br /&gt;–        Software companies are constantly loosing and hiring workforce so how can they work if they keep loosing “documentation” which is on people´s minds ?&lt;br /&gt;&lt;br /&gt;–        How can they know the "what", "where" and "how" in the source code ?&lt;br /&gt;&lt;br /&gt;Some years have passed and this methodology has matured and besides that other good methodologies of the same family like Scrum have come up too.&lt;br /&gt;It called my attention that many state-of-art tech companies like Google and Yahoo! were working with Scrum and I started to get curious to know what it is about.&lt;br /&gt;&lt;br /&gt;Five years later I decided to attend to a presentation about XP Programming in order to get a broader picture about it. It helped me to remove some miths I had such as the lack of documentation. Actually the Agile Methodology do not remove the activity of producing documentation but it just gave a different meaning for the documentation. The documentation should be provided if relevant for developers.  It doesn´t have to include fancy diagrams but only the necessary information such as what is the system about, how to compile source-code, or other information that it is not self-explained in the system.&lt;br /&gt;&lt;br /&gt;After reading "The Toyota Way" I noticed that agile methodologies was greatly inspired by this administration model. This model is basically driven to reduce waste, in other words, we should do only the necessary to accomplish our objectives, no more or no less. By reducing waste we are also reducing unnecessary work what can mean different things depending on our project such as no documentation, few documentation, no models, etc.&lt;br /&gt;&lt;br /&gt;Therefore to be lean (and consequently agile), one must think on what tasks are been carried out and what tasks in the process should be eliminated if they have no value. Read the book above to have a good idea of the process.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-2019315421038352809?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2H-B2XSsWisM0eomzIyxOtYtNzs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2H-B2XSsWisM0eomzIyxOtYtNzs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2H-B2XSsWisM0eomzIyxOtYtNzs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2H-B2XSsWisM0eomzIyxOtYtNzs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/XOi6voPxTQQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/2019315421038352809/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=2019315421038352809" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/2019315421038352809?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/2019315421038352809?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/XOi6voPxTQQ/extreme-programming-impressions.html" title="Extreme Programming Impressions" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>3</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2009/09/extreme-programming-impressions.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8DRHw-fip7ImA9WxFQFEg.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-5138799917245985469</id><published>2009-08-27T16:05:00.000-07:00</published><updated>2010-05-09T19:01:15.256-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-09T19:01:15.256-07:00</app:edited><title>DynamicProxy: An Elegant Solution for Session/Transaction/Exception Management in NHibernate (or any other ORM)</title><content type="html">Session management is a well solved problem for web applications and many detailed solutions can be found in the internet. The same is not true for winforms applications. Although there are solutions available in the internet, many of them are theoretical or just “complicated” for the medium programmer. Besides that it was difficult to find a solution (I have never found one) that could work for both web and winforms applications.&lt;br /&gt;
&lt;br /&gt;
After a while (days), it came up to me the idea of using service proxies with &lt;b&gt;Castle Dynamic Proxies&lt;/b&gt;. It turned out to be the easiest and cleanest approach I could think of because it has the ability to inject (aspects) behaviour around the service methods.&lt;br /&gt;
&lt;br /&gt;
The idea can be coded in the following way:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;Service classes with standard namespace and virtual methods&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;namespace Sample.Service
{
  public class SystemLogRegistrationService
  {
    public virtual void Modify(long codLogSistema)
    {
      SystemLog systemLog = Repository.Get&lt;logsistema&gt;().Load(codLogSistema);            
      systemLog.SetMachine = "MAQUINA" + DateTime.Now;
      systemLog.SetUserName = "PESSOA" + DateTime.Now;            
      systemLog.SetSystemName = "SISTEMA" + DateTime.Now;
      Repository.Get&lt;logsistema&gt;().Save(systemLog);            
    }
  }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Do not get distracted with the service code. The important thing to notice above is that the service does not contain anything else other than processing the domain classes (in this case, SystemLog). Also note that &lt;b&gt;all service methods must be virtual&lt;/b&gt;. Without that, dynamic proxy won't work for these methods. The details of Repository implementation are out of the scope of this article and this subject is covered in enough details in several articles throughout the internet. (You can also send me a comment or email if you need information about that)&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;Usage Example&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
In order to make use of proxified services, one must create some kind of generator  whose creation will be explained next. The ProxyGenerator below is a simple static class for didactic purposes that is responsible for dynamically generate proxies from a given type injecting the necessary aspects such as session/transaction management and exception handling or any other aspect you might think about.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;SomeService serv = ProxyGenerator.InjectSessionTransactionExceptionAspects &amp;lt SomeService &amp;gt ();
serv.Modify(12048); // &lt;= Modify method has session/transaction/exception management
&lt;/pre&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;Creating a proxy service factory&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;The proxy generator can be implemented using Castle Dynamic Proxy API.

&lt;pre class="brush:csharp"&gt;using System;
using Castle.DynamicProxy;

namespace Sample.Persistence
{
  public static class ProxyGenerator 
  {
    private static ProxyGenerator _generator = new ProxyGenerator();        
    public static TService InjectSessionTransactionExceptionAspects &amp;lt TService &amp;gt ()
    {
      return (TService)_generator.CreateClassProxy(
        typeof(TService),
        new SessionTransactionExceptionAspect());    
    }
  }
}
&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;An interceptor for the service class methods&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;pre class="brush:csharp"&gt;using System;
using Castle.DynamicProxy;
using NHibernate;
using NHibernate.Context;

namespace Sample.Persistence
{
  /// &lt;summary&gt;
  /// Intercepts service methods (must be virtual) and inject
  /// session / transaction and exception aspects
  /// &lt;/summary&gt;
  public class SessionTransactionExceptionAspect: IInterceptor
  {
    /// &lt;summary&gt;
    /// Intercepts service methods and adds the following behaviors
    /// &gt;&gt;&gt; Before executing a method:
    ///     * opens session
    ///     * begins transaction
    /// &gt;&gt;&gt; After executing method:
    ///     * Commits transaction
    /// &gt;&gt;&gt; In case there is exception
    ///     * Rollbacks transaction
    ///     * Handles exception
    /// &gt;&gt;&gt; At the end
    ///     * Closes session
    /// &lt;/summary&gt;
    public object Intercept(IInvocation invocation, params object[] args)
    {
      object retorno = null;
      ITransaction tx = null;
      try
      {          
        CurrentSessionContext.Bind(SessionFactory.Instance.OpenSession());
        tx = SessionFactory.Instance.GetCurrentSession().BeginTransaction();
        retorno = invocation.Proceed(args);
        tx.Commit();
      }
      catch (Exception exception)
      {
        if (tx != null) { tx.Rollback(); }
          throw exception;
      }
      finally
      {
        ISession s = SessionFactory.Instance.GetCurrentSession();
        s.Close();
        CurrentSessionContext.Unbind(s.SessionFactory);
      }
      return retorno;
    }
  }
}
&lt;/pre&gt;Above is the center of the whole idea. The interceptor class above captures only the service methods and ignores the rest. The following tasks are executed inside a try-catch-finally: (when it is a service method)
&lt;ul&gt;&lt;li&gt;Session is created&lt;/li&gt;
&lt;li&gt;Transaction is initialized&lt;/li&gt;
&lt;li&gt;The method itself is executed&lt;/li&gt;
&lt;li&gt;if method is ok, transaction is confirmed&lt;/li&gt;
&lt;li&gt;if there is exception, transaction is cancelled and exception is handled&lt;/li&gt;
&lt;li&gt;Finally session is  closed &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-5138799917245985469?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/NHmjHiPKdh7xSUJIj6a07ZMqpdM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NHmjHiPKdh7xSUJIj6a07ZMqpdM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/NHmjHiPKdh7xSUJIj6a07ZMqpdM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NHmjHiPKdh7xSUJIj6a07ZMqpdM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/3FsRsr-doGI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/5138799917245985469/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=5138799917245985469" title="7 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/5138799917245985469?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/5138799917245985469?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/3FsRsr-doGI/dynamicproxy-elegant-solution-for.html" title="DynamicProxy: An Elegant Solution for Session/Transaction/Exception Management in NHibernate (or any other ORM)" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>7</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2009/08/dynamicproxy-elegant-solution-for.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkMMRXw5fCp7ImA9WxFTEUo.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-8832126547532467560</id><published>2009-08-21T19:27:00.000-07:00</published><updated>2010-04-01T18:08:04.224-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-01T18:08:04.224-07:00</app:edited><title>Avoid "Tall" DAO Factories</title><content type="html">A "tall" DAO factory can be defined as a big class that contains too much methods for each business class that compounds your domain model.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp;gutter: false"&gt;public class DAOFactory
{
IClass1DAO GetClass1DAO() { ... }
IClass2DAO GetClass2DAO() { ... }
IClass3DAO GetClass3DAO() { ... }
IClass4DAO GetClass4DAO() { ... }
IClass5DAO GetClass5DAO() { ... }
IClass6DAO GetClass6DAO() { ... }
IClass7DAO GetClass7DAO() { ... }
IClass8DAO GetClass8DAO() { ... }
IClass9DAO GetClass9DAO() { ... }
IClass10DAO GetClass10DAO() { ... }
: : : :
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Besides big, these kind of class should be modified every time a new domain class is added to your system.&lt;br /&gt;
In order to avoid that to happen, one good option is to use a generic method for all DAO interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp;gutter: false"&gt;public class DAOFactory
{
ICommonDAO GetDAO &amp;lt; I &amp;gt; ( ) where I : ICommonDAO { ... }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
The action of searching the corresponding DAO interface implementation can be easily achieved by using .NET reflection support for Assemblies and Types.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-8832126547532467560?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0rjhRErlUnx5t4YzG20zvd4byes/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0rjhRErlUnx5t4YzG20zvd4byes/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0rjhRErlUnx5t4YzG20zvd4byes/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0rjhRErlUnx5t4YzG20zvd4byes/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/dicfPE_ewVA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/8832126547532467560/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=8832126547532467560" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/8832126547532467560?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/8832126547532467560?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/dicfPE_ewVA/avoid-tall-dao-factories.html" title="Avoid &quot;Tall&quot; DAO Factories" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2009/08/avoid-tall-dao-factories.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkUERnw_eCp7ImA9WxJVE04.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-6394661598185996990</id><published>2009-06-13T12:55:00.000-07:00</published><updated>2009-06-29T19:50:07.240-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-06-29T19:50:07.240-07:00</app:edited><title>Agile Modeling in Software Projects</title><content type="html">Recently Jeff Sutherland mentioned another certification for software programmers since Scrum does not include software engineer techniques but very present in XP (extreme programming) management. That is probably the reason why many software developers work with Scrum and XP methodologies together.&lt;br /&gt;&lt;br /&gt;However although XP is very software-programming oriented it is still not enough to have a good software design in large systems projects. Additionally in many organizations it is very difficult to find a product owner that fully understand the business rules and can manage the software functionalities.&lt;br /&gt;&lt;br /&gt;In order to efficiently use Scrum, there must be someone responsible for understanding the business. If there is no product owner, one employee must be chosen to study and logically model the business. That is exactly why a good business modeling is imperative before any large software development.&lt;br /&gt;&lt;br /&gt;Good software design and business understanding prevents or reduces significantly re-work tasks. It is considered wasted work since these tasks do not devliver anything useful to the client and often happens when developers did not captured well the business rules.&lt;br /&gt;&lt;br /&gt;Thus the following software development process is proposed to match DDD and agile approach. In this software process, there can be product owners, developers and scrum masters just like original Scrum the difference is that before the sprints (see Scrum reference) can start, a long DDD session is necessary in order to produce a good business model.&lt;br /&gt;&lt;br /&gt;Briefly describing the following steps should be taken:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;A selected person assumes the role of Product Owner&lt;/li&gt;&lt;li&gt;Product Owner becomes responsible for studying and building a business model&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Product Owner writes all the system features using User Stories (from XP)&lt;/li&gt;&lt;li&gt;Product Owner schedules a Planning Meeting with the Scrum Master and Developers to present User Stories and the Business Model&lt;/li&gt;&lt;li&gt;Scrum Master schedules a Sprint Meeting with developers to plan the Next Sprint based on the Stories&lt;/li&gt;&lt;li&gt;Developers begin the Sprint  (from 1 to 2 weeks)&lt;/li&gt;&lt;li&gt;Scrum Master Organizes Daily Meetings with Developers (just like Scrum)&lt;/li&gt;&lt;li&gt;At the end of the Spring, Scrum Master schedules a Weekly Meeting to present the system to the Product Owner but it also includes the developers of the project who makes considerations about the system presented&lt;/li&gt;&lt;li&gt;Scrum Master organized a Retrospective Meeting with the developers to discuss what went wrong or right with the Sprint and then they start planning the next Sprint.&lt;/li&gt;&lt;li&gt;Go to Step 6 until Product Owner gets satisfied&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-6394661598185996990?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/KtM5LsmFBj3hxz0Nb_mYKhmOC6I/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KtM5LsmFBj3hxz0Nb_mYKhmOC6I/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/KtM5LsmFBj3hxz0Nb_mYKhmOC6I/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KtM5LsmFBj3hxz0Nb_mYKhmOC6I/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/9AHTdQHSHy4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/6394661598185996990/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=6394661598185996990" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/6394661598185996990?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/6394661598185996990?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/9AHTdQHSHy4/domain-driven-design-and-agile-project.html" title="Agile Modeling in Software Projects" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>2</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2009/06/domain-driven-design-and-agile-project.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkMBQng7fSp7ImA9WxJVE04.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-3102517400544391123</id><published>2009-06-10T17:34:00.000-07:00</published><updated>2009-06-29T19:54:13.605-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-06-29T19:54:13.605-07:00</app:edited><title>How the repository pattern works ?</title><content type="html">The classes that represent the elements of a domain must contain all the business logic inside it such as tax calculation, name validation, etc. However in many circumstances it is also necessary to access data in order to complete the business logic inside these classes.&lt;br /&gt;&lt;br /&gt;Take the example below:&lt;br /&gt;&lt;br /&gt;Suppose I want to create an instance from the &lt;span style="font-style: italic;"&gt;Client class&lt;/span&gt; and that clients must have a name and an address (there may be more information but lets stay with those two data for simplification purposes).&lt;br /&gt;So, this could be instantiated like: (C# code)&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;// Open database connection (and Begin Transaction)&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;SessionManager&lt;/span&gt;.Open( );&lt;br /&gt;: : :&lt;br /&gt;// Parameters are: name, zipcode, adress number, address complement, country&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Client&lt;/span&gt; client = new &lt;span style="font-weight: bold;"&gt;Client&lt;/span&gt;(“New Client”,”12500”,12,“Room 14”,&lt;span style="font-weight: bold;"&gt;Country&lt;/span&gt;.US);&lt;br /&gt;: : :&lt;br /&gt;// Close database connection (and Commit Transaction)&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;SessionManager&lt;/span&gt;.Close( );&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Although simple, the line above hides many steps such as:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Check if client name is valid &lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Check if zipcode exists in the county US&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Check if address number is correct&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Check if addres complement id correct&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Check if there are clients with the same name and address&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Proceed with the client creation&lt;/li&gt;&lt;/ul&gt;However in order to complete some of this steps, the &lt;span style="font-style: italic;"&gt;Client&lt;/span&gt; object should be able to access the data layer and that is the responsibility of the repositories. According to Martin Fowler's website: &lt;span style="font-style: italic;"&gt;Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reference&lt;/span&gt;: http://www.martinfowler.com/eaaCatalog/repository.html&lt;br /&gt;&lt;br /&gt;In order to make it possible the code line above, an &lt;span style="font-style: italic;"&gt;Address&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;Client clas&lt;/span&gt;s must be implemented.&lt;br /&gt;&lt;br /&gt;See full code listing below:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;// Address is a value object used by Client class&lt;br /&gt;public class &lt;span style="font-weight: bold;"&gt;Address&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;     public &lt;span style="font-weight: bold;"&gt;Address&lt;/span&gt;(string zipCodeNumber,int number,string addrComplement)&lt;br /&gt;     {&lt;br /&gt;            // Check if zipcode number exists in the country  (ZipCode Repository uses SessionManager inside it)&lt;br /&gt;            &lt;span style="font-weight: bold;"&gt;IZipCodeRepository&lt;/span&gt; zipCodeRepository = &lt;span style="font-weight: bold;"&gt;RepositoryManager&lt;/span&gt;.GetRepository&lt;zipcode&gt;( );&lt;br /&gt;            &lt;span style="font-weight: bold;"&gt;ZipCode&lt;/span&gt; zipCode = zipCodeRepository.Get(zipCodeNumber,country);&lt;br /&gt;            if (zipCode == null) { throw new &lt;span style="font-weight: bold;"&gt;NonExistentZipCodeException&lt;/span&gt;(zipCodeNumber,country);&lt;br /&gt;            // Check if address number is correct&lt;br /&gt;            if  (number &lt;= 0) { throw new &lt;span style="font-weight: bold;"&gt;InvalidAddressNumberException&lt;/span&gt;(number); }               &lt;br /&gt;            // Check if address complement is correct&lt;br /&gt;            if (complement.Trim( ) == string.Empty) { throw new  &lt;span style="font-weight: bold;"&gt;InvalidAddressComplementException&lt;/span&gt;(addrComplement)); }&lt;br /&gt;            // Sets values&lt;br /&gt;       this._zipCode = zipCode;&lt;br /&gt;       this._number = number;&lt;br /&gt;            this._complement = complement;&lt;br /&gt;     }&lt;br /&gt;     private &lt;span style="font-weight: bold;"&gt;ZipCode&lt;/span&gt; _zipCode = null;&lt;br /&gt;     public &lt;span style="font-weight: bold;"&gt;ZipCode&lt;/span&gt; ZipCode get { return _zipCode; }&lt;br /&gt;     private int _number = 0;&lt;br /&gt;     public int Number { get { return _number; } }&lt;br /&gt;     private string _complement = string.Empty;&lt;br /&gt;     public string Complement { get { return _complement; } }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Now the Client class&lt;br /&gt;public class &lt;span style="font-weight: bold;"&gt;Client&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;     private long _id;&lt;br /&gt;     public long Id { get { return id; } set { this.id = value; } }&lt;br /&gt;     private string _name = string.Empty;&lt;br /&gt;     public Name&lt;br /&gt;     {        &lt;br /&gt;            get { return _name; }  &lt;br /&gt;            // Check if name is valid    &lt;br /&gt;            set&lt;br /&gt;            {&lt;br /&gt;                   if (name.Trim( ) == string.Empty) { throw new &lt;span style="font-weight: bold;"&gt;InvalidNameException&lt;/span&gt;(); }               &lt;br /&gt;                   // Check if there are Clients with same name and address               &lt;br /&gt;                   &lt;span style="font-weight: bold;"&gt;IClientRepository&lt;/span&gt; clientRepository = RepositoryManager.GetRepository&lt;client&gt;();&lt;br /&gt;                   bool exists = clientRepository.ClientExists(name,zipCodeNumber,number,addrComplement,country);&lt;br /&gt;                   if (exists) { throw new &lt;span style="font-weight: bold;"&gt;ClientExistsException&lt;/span&gt;( ); }&lt;br /&gt;                   this._name = value;         &lt;br /&gt;                &lt;br /&gt;             }&lt;br /&gt;     }&lt;br /&gt;     private &lt;span style="font-weight: bold;"&gt;Address&lt;/span&gt; _address;&lt;br /&gt;     public Address { get { return _address; } }&lt;br /&gt;     public &lt;span style="font-weight: bold;"&gt;Client&lt;/span&gt;(string name,string zipCodeNumber,int number,string addrComplement,Country country)&lt;br /&gt;     {       &lt;br /&gt;             // Creates a Client&lt;br /&gt;             this.Address = new Address(zipCodeNumber,number,addrComplement,country);&lt;br /&gt;             this.Name = name;     &lt;br /&gt;      }&lt;br /&gt;}&lt;br /&gt;&lt;/client&gt;&lt;/zipcode&gt;&lt;/pre&gt;&lt;br /&gt;Repositories have at least two advantages:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;It removes data specific code from the domain classes which are concerned only about business logic&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;It allows unit tests since repositories are referred as interfaces in domain classes and thus fake repositories can be created without depend on database connection&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-3102517400544391123?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/R05wmQEORx9sXHNVn3LDZ88R9JY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/R05wmQEORx9sXHNVn3LDZ88R9JY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/R05wmQEORx9sXHNVn3LDZ88R9JY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/R05wmQEORx9sXHNVn3LDZ88R9JY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/nps54ScYAaU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/3102517400544391123/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=3102517400544391123" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/3102517400544391123?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/3102517400544391123?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/nps54ScYAaU/how-repository-pattern-works.html" title="How the repository pattern works ?" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2009/06/how-repository-pattern-works.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYNQX44fyp7ImA9WxVVGUw.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-8442411478405686557</id><published>2009-03-12T18:36:00.000-07:00</published><updated>2009-03-12T19:09:50.037-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-12T19:09:50.037-07:00</app:edited><title>Using .NET Nullable Types with NHibernate 1.2</title><content type="html">Originally, NHibernate 1.2 does not support nullable types from .NET such as &lt;span style="font-weight: bold;"&gt;DateTime?, int?, bool?&lt;/span&gt;, etc. but that can be solved by implementing specific NHibernate specific user types.&lt;br /&gt;Not all nullable user types are listed for all .NET nullable types are listed below. But it can be easily done by following the example specially for numeric types.&lt;br /&gt;However if you need help you jut send an email.&lt;br /&gt;&lt;br /&gt;Nullable user types code listings:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;NullableDateTimeType.cs&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;﻿using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Text;&lt;br /&gt;using NHibernate.UserTypes;&lt;br /&gt;using NHibernate;&lt;br /&gt;using System.Data;&lt;br /&gt;using NHibernate.SqlTypes;&lt;br /&gt;&lt;br /&gt;namespace Utilitario.GerenciaDados&lt;br /&gt;{&lt;br /&gt;  public class NullableDateTimeType : IUserType&lt;br /&gt;  {&lt;br /&gt;      #region IUserType Members&lt;br /&gt;      public bool Equals(object x, object y)&lt;br /&gt;      {&lt;br /&gt;          return object.Equals(x, y);&lt;br /&gt;      }&lt;br /&gt;      public int GetHashCode(object x)&lt;br /&gt;      {&lt;br /&gt;          return x.GetHashCode();&lt;br /&gt;      }&lt;br /&gt;      public object NullSafeGet(IDataReader rs, string[] names, object owner)&lt;br /&gt;      {&lt;br /&gt;          //object valor = NHibernateUtil.DateTime.NullSafeGet(rs, names[0]);&lt;br /&gt;          object valor = null;&lt;br /&gt;          if (rs[names[0]] != DBNull.Value)&lt;br /&gt;              valor = Convert.ToDateTime(rs[names[0]]);&lt;br /&gt;&lt;br /&gt;          DateTime? dateTime = null;&lt;br /&gt;&lt;br /&gt;          if (valor != null)&lt;br /&gt;          {&lt;br /&gt;              dateTime = (DateTime)valor;&lt;br /&gt;          }&lt;br /&gt;          return dateTime;&lt;br /&gt;      }&lt;br /&gt;      public void NullSafeSet(IDbCommand cmd, object value, int index)&lt;br /&gt;      {&lt;br /&gt;          if (value == null)&lt;br /&gt;          {&lt;br /&gt;              NHibernateUtil.String.NullSafeSet(cmd, null, index);&lt;br /&gt;          }&lt;br /&gt;          else&lt;br /&gt;          {&lt;br /&gt;              DateTime? dateTime = (DateTime)value;&lt;br /&gt;              NHibernateUtil.AnsiString.NullSafeSet(cmd, dateTime.Value.ToString("yyyy/MM/dd HH:mm:ss.fff"), index);&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;      public object DeepCopy(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public object Replace(object original, object target, object owner)&lt;br /&gt;      {&lt;br /&gt;          return original;&lt;br /&gt;      }&lt;br /&gt;      public object Assemble(object cached, object owner)&lt;br /&gt;      {&lt;br /&gt;          return cached;&lt;br /&gt;      }&lt;br /&gt;      public object Disassemble(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public SqlType[] SqlTypes&lt;br /&gt;      {&lt;br /&gt;          get { return new SqlType[] { new StringSqlType() }; }&lt;br /&gt;      }&lt;br /&gt;      public Type ReturnedType&lt;br /&gt;      {&lt;br /&gt;          get { return typeof(string); }&lt;br /&gt;      }&lt;br /&gt;      public bool IsMutable&lt;br /&gt;      {&lt;br /&gt;          get { return false; }&lt;br /&gt;      }&lt;br /&gt;      #endregion&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;NullableBooleanType.cs&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Text;&lt;br /&gt;using NHibernate.UserTypes;&lt;br /&gt;using NHibernate;&lt;br /&gt;using System.Data;&lt;br /&gt;using NHibernate.SqlTypes;&lt;br /&gt;&lt;br /&gt;namespace Utilitario.GerenciaDados&lt;br /&gt;{&lt;br /&gt;  public class NullableBooleanType : IUserType&lt;br /&gt;  {&lt;br /&gt;      #region IUserType Members&lt;br /&gt;      public bool Equals(object x, object y)&lt;br /&gt;      {&lt;br /&gt;          return object.Equals(x, y);&lt;br /&gt;      }&lt;br /&gt;      public int GetHashCode(object x)&lt;br /&gt;      {&lt;br /&gt;          return x.GetHashCode();&lt;br /&gt;      }&lt;br /&gt;      public object NullSafeGet(IDataReader rs, string[] names, object owner)&lt;br /&gt;      {&lt;br /&gt;          object valor = NHibernateUtil.Boolean.NullSafeGet(rs, names[0]);&lt;br /&gt;          bool? caracter = null;&lt;br /&gt;          if (valor != null)&lt;br /&gt;          {&lt;br /&gt;              caracter = (bool)valor;&lt;br /&gt;          }&lt;br /&gt;          return caracter;&lt;br /&gt;      }&lt;br /&gt;      public void NullSafeSet(IDbCommand cmd, object value, int index)&lt;br /&gt;      {&lt;br /&gt;          if (value == null)&lt;br /&gt;          {&lt;br /&gt;              NHibernateUtil.Boolean.NullSafeSet(cmd, null, index);&lt;br /&gt;          }&lt;br /&gt;          else&lt;br /&gt;          {&lt;br /&gt;              bool? caracter = (bool)value;&lt;br /&gt;              NHibernateUtil.Boolean.NullSafeSet(cmd, caracter.Value, index);&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;      public object DeepCopy(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public object Replace(object original, object target, object owner)&lt;br /&gt;      {&lt;br /&gt;          return original;&lt;br /&gt;      }&lt;br /&gt;      public object Assemble(object cached, object owner)&lt;br /&gt;      {&lt;br /&gt;          return cached;&lt;br /&gt;      }&lt;br /&gt;      public object Disassemble(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public SqlType[] SqlTypes&lt;br /&gt;      {&lt;br /&gt;          get { return new SqlType[] { new StringSqlType() }; }&lt;br /&gt;      }&lt;br /&gt;      public Type ReturnedType&lt;br /&gt;      {&lt;br /&gt;          get { return typeof(string); }&lt;br /&gt;      }&lt;br /&gt;      public bool IsMutable&lt;br /&gt;      {&lt;br /&gt;          get { return false; }&lt;br /&gt;      }&lt;br /&gt;      #endregion&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;NullableCharType.cs&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Text;&lt;br /&gt;using NHibernate.UserTypes;&lt;br /&gt;using NHibernate;&lt;br /&gt;using System.Data;&lt;br /&gt;using NHibernate.SqlTypes;&lt;br /&gt;&lt;br /&gt;namespace Utilitario.GerenciaDados&lt;br /&gt;{&lt;br /&gt;  public class NullableCharType : IUserType&lt;br /&gt;  {&lt;br /&gt;      #region IUserType Members&lt;br /&gt;      public bool Equals(object x, object y)&lt;br /&gt;      {&lt;br /&gt;          return object.Equals(x, y);&lt;br /&gt;      }&lt;br /&gt;      public int GetHashCode(object x)&lt;br /&gt;      {&lt;br /&gt;          return x.GetHashCode();&lt;br /&gt;      }&lt;br /&gt;      public object NullSafeGet(IDataReader rs, string[] names, object owner)&lt;br /&gt;      {&lt;br /&gt;          object valor = NHibernateUtil.Character.NullSafeGet(rs, names[0]);&lt;br /&gt;          Char? caracter = null;&lt;br /&gt;          if (valor != null)&lt;br /&gt;          {&lt;br /&gt;              caracter = (Char)valor;&lt;br /&gt;          }&lt;br /&gt;         return caracter;&lt;br /&gt;      }&lt;br /&gt;      public void NullSafeSet(IDbCommand cmd, object value, int index)&lt;br /&gt;      {  &lt;br /&gt;          if (value == null)&lt;br /&gt;          {&lt;br /&gt;               NHibernateUtil.Character.NullSafeSet(cmd, null, index);&lt;br /&gt;          }&lt;br /&gt;          else&lt;br /&gt;          {&lt;br /&gt;              Char? caracter = (Char)value;&lt;br /&gt;              NHibernateUtil.Character.NullSafeSet(cmd, caracter.Value, index);&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;      public object DeepCopy(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public object Replace(object original, object target, object owner)&lt;br /&gt;      {&lt;br /&gt;          return original;&lt;br /&gt;      }&lt;br /&gt;      public object Assemble(object cached, object owner)&lt;br /&gt;      {&lt;br /&gt;          return cached;&lt;br /&gt;      }&lt;br /&gt;      public object Disassemble(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public SqlType[] SqlTypes&lt;br /&gt;      {&lt;br /&gt;          get { return new SqlType[] { new StringSqlType() }; }&lt;br /&gt;      }&lt;br /&gt;      public Type ReturnedType&lt;br /&gt;      {&lt;br /&gt;          get { return typeof(string); }&lt;br /&gt;      }&lt;br /&gt;      public bool IsMutable&lt;br /&gt;      {&lt;br /&gt;          get { return false; }&lt;br /&gt;      }&lt;br /&gt;      #endregion&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;NullableDecimalType.cs&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Text;&lt;br /&gt;using NHibernate.UserTypes;&lt;br /&gt;using System.Data;&lt;br /&gt;using NHibernate.Util;&lt;br /&gt;using NHibernate;&lt;br /&gt;using NHibernate.SqlTypes;&lt;br /&gt;&lt;br /&gt;namespace Utilitario.GerenciaDados&lt;br /&gt;{&lt;br /&gt;  public class NullableDecimalType : IUserType&lt;br /&gt;  {&lt;br /&gt;      #region IUserType Members&lt;br /&gt;      public bool Equals(object x, object y)&lt;br /&gt;      {&lt;br /&gt;          return object.Equals(x, y);&lt;br /&gt;      }&lt;br /&gt;      public int GetHashCode(object x)&lt;br /&gt;      {&lt;br /&gt;          return x.GetHashCode();&lt;br /&gt;      }&lt;br /&gt;      public object NullSafeGet(IDataReader rs, string[] names, object owner)&lt;br /&gt;      {&lt;br /&gt;          object valor = NHibernateUtil.Decimal.NullSafeGet(rs, names[0]);&lt;br /&gt;          Decimal? inteiro = null;&lt;br /&gt;          if (valor != null)&lt;br /&gt;          {&lt;br /&gt;              inteiro = (Decimal)valor;&lt;br /&gt;          }&lt;br /&gt;          return inteiro;&lt;br /&gt;      }&lt;br /&gt;      public void NullSafeSet(IDbCommand cmd, object value, int index)&lt;br /&gt;      {&lt;br /&gt;          if (value == null)&lt;br /&gt;          {&lt;br /&gt;              NHibernateUtil.Decimal.NullSafeSet(cmd, null, index);&lt;br /&gt;          }&lt;br /&gt;          else&lt;br /&gt;          {&lt;br /&gt;              Decimal? inteiro = (Decimal)value;&lt;br /&gt;              NHibernateUtil.Decimal.NullSafeSet(cmd, inteiro.Value.ToString().Replace(',','.'), index);&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;      public object DeepCopy(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public object Replace(object original, object target, object owner)&lt;br /&gt;      {&lt;br /&gt;          return original;&lt;br /&gt;      }&lt;br /&gt;      public object Assemble(object cached, object owner)&lt;br /&gt;      {&lt;br /&gt;          return cached;&lt;br /&gt;      }&lt;br /&gt;      public object Disassemble(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public SqlType[] SqlTypes&lt;br /&gt;      {&lt;br /&gt;          get { return new SqlType[] { new StringSqlType() }; }&lt;br /&gt;      }&lt;br /&gt;      public Type ReturnedType&lt;br /&gt;      {&lt;br /&gt;          get { return typeof(string); }&lt;br /&gt;      }&lt;br /&gt;      public bool IsMutable&lt;br /&gt;      {&lt;br /&gt;          get { return false; }&lt;br /&gt;      }&lt;br /&gt;      #endregion&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;NullableDoubleType.cs&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Text;&lt;br /&gt;using NHibernate.UserTypes;&lt;br /&gt;using NHibernate;&lt;br /&gt;using NHibernate.SqlTypes;&lt;br /&gt;using System.Data;&lt;br /&gt;&lt;br /&gt;namespace Utilitario.GerenciaDados&lt;br /&gt;{&lt;br /&gt;  public class NullableDoubleType : IUserType&lt;br /&gt;  {&lt;br /&gt;      #region IUserType Members&lt;br /&gt;      public bool Equals(object x, object y)&lt;br /&gt;      {&lt;br /&gt;          return object.Equals(x, y);&lt;br /&gt;      }&lt;br /&gt;      public int GetHashCode(object x)&lt;br /&gt;      {&lt;br /&gt;          return x.GetHashCode();&lt;br /&gt;      }&lt;br /&gt;      public object NullSafeGet(IDataReader rs, string[] names, object owner)&lt;br /&gt;      {&lt;br /&gt;          object valor = NHibernateUtil.Double.NullSafeGet(rs, names[0]);&lt;br /&gt;          Double? valorD = null;&lt;br /&gt;          if (valor != null)&lt;br /&gt;          {&lt;br /&gt;              valorD = (double)valor;&lt;br /&gt;          }&lt;br /&gt;          return valorD;&lt;br /&gt;      }&lt;br /&gt;      public void NullSafeSet(IDbCommand cmd, object value, int index)&lt;br /&gt;      {&lt;br /&gt;          if (value == null)&lt;br /&gt;          {&lt;br /&gt;              NHibernateUtil.Double.NullSafeSet(cmd, null, index);&lt;br /&gt;          }&lt;br /&gt;          else&lt;br /&gt;          {&lt;br /&gt;              Double? valor = (Double)value;&lt;br /&gt;              NHibernateUtil.Double.NullSafeSet(cmd, valor.Value.ToString().Replace(',','.'), index);&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;      public object DeepCopy(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public object Replace(object original, object target, object owner)&lt;br /&gt;      {&lt;br /&gt;          return original;&lt;br /&gt;      }&lt;br /&gt;      public object Assemble(object cached, object owner)&lt;br /&gt;      {&lt;br /&gt;          return cached;&lt;br /&gt;      }&lt;br /&gt;      public object Disassemble(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public SqlType[] SqlTypes&lt;br /&gt;      {&lt;br /&gt;          get { return new SqlType[] { new StringSqlType() }; }&lt;br /&gt;      }&lt;br /&gt;      public Type ReturnedType&lt;br /&gt;      {&lt;br /&gt;          get { return typeof(string); }&lt;br /&gt;      }&lt;br /&gt;      public bool IsMutable&lt;br /&gt;      {&lt;br /&gt;          get { return false; }&lt;br /&gt;      }&lt;br /&gt;      #endregion&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-weight: bold;"&gt;NullableInt32Type.cs&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Text;&lt;br /&gt;using NHibernate.UserTypes;&lt;br /&gt;using System.Data;&lt;br /&gt;using NHibernate.Util;&lt;br /&gt;using NHibernate;&lt;br /&gt;using NHibernate.SqlTypes;&lt;br /&gt;&lt;br /&gt;namespace Utilitario.GerenciaDados&lt;br /&gt;{&lt;br /&gt;  public class NullableInt32Type : IUserType&lt;br /&gt;  {&lt;br /&gt;      #region IUserType Members&lt;br /&gt;      public bool Equals(object x, object y)&lt;br /&gt;      {&lt;br /&gt;          return object.Equals(x, y);&lt;br /&gt;      }&lt;br /&gt;      public int GetHashCode(object x)&lt;br /&gt;      {&lt;br /&gt;          return x.GetHashCode();&lt;br /&gt;      }&lt;br /&gt;      public object NullSafeGet(IDataReader rs, string[] names, object owner)&lt;br /&gt;      {&lt;br /&gt;          object valor = NHibernateUtil.Int32.NullSafeGet(rs, names[0]);&lt;br /&gt;          Int32? inteiro = null;&lt;br /&gt;          if (valor != null)&lt;br /&gt;          {&lt;br /&gt;              inteiro = (Int32)valor;&lt;br /&gt;          }&lt;br /&gt;          return inteiro;&lt;br /&gt;      }&lt;br /&gt;      public void NullSafeSet(IDbCommand cmd, object value, int index)&lt;br /&gt;      {&lt;br /&gt;          if (value == null)&lt;br /&gt;          {&lt;br /&gt;              NHibernateUtil.Int32.NullSafeSet(cmd, null, index);&lt;br /&gt;          }&lt;br /&gt;          else&lt;br /&gt;          {&lt;br /&gt;              Int32? inteiro = (int)value;&lt;br /&gt;              NHibernateUtil.Int32.NullSafeSet(cmd, inteiro.Value, index);&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;      public object DeepCopy(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public object Replace(object original, object target, object owner)&lt;br /&gt;      {&lt;br /&gt;          return original;&lt;br /&gt;      }&lt;br /&gt;      public object Assemble(object cached, object owner)&lt;br /&gt;      {&lt;br /&gt;          return cached;&lt;br /&gt;      }&lt;br /&gt;      public object Disassemble(object value)&lt;br /&gt;      {&lt;br /&gt;          return value;&lt;br /&gt;      }&lt;br /&gt;      public SqlType[] SqlTypes&lt;br /&gt;      {&lt;br /&gt;          get { return new SqlType[] { new StringSqlType() }; }&lt;br /&gt;      }&lt;br /&gt;      public Type ReturnedType&lt;br /&gt;      {&lt;br /&gt;          get { return typeof(string); }&lt;br /&gt;      }&lt;br /&gt;      public bool IsMutable&lt;br /&gt;      {&lt;br /&gt;          get { return false; }&lt;br /&gt;      }&lt;br /&gt;      #endregion&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-8442411478405686557?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-YownI4Bnh2lpjHI_LH80GXSu0I/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-YownI4Bnh2lpjHI_LH80GXSu0I/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-YownI4Bnh2lpjHI_LH80GXSu0I/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-YownI4Bnh2lpjHI_LH80GXSu0I/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/xVL0JYxWUmI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/8442411478405686557/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=8442411478405686557" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/8442411478405686557?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/8442411478405686557?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/xVL0JYxWUmI/using-net-nullable-types-with.html" title="Using .NET Nullable Types with NHibernate 1.2" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2009/03/using-net-nullable-types-with.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkQMSHs4cCp7ImA9WxVTE0w.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-7269830269714291107</id><published>2008-12-26T09:48:00.000-08:00</published><updated>2008-12-26T09:59:49.538-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-26T09:59:49.538-08:00</app:edited><title>Extremely Short Introduction for Ruby on Rails</title><content type="html">&lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }   H1 { margin-bottom: 0.08in }   H1.western { font-family: "Arial", sans-serif; font-size: 16pt }   H1.cjk { font-family: "MS Mincho"; font-size: 16pt }   H1.ctl { font-family: "Tahoma"; font-size: 16pt }   H2 { margin-bottom: 0.08in }   H2.western { font-family: "Arial", sans-serif; font-size: 14pt; font-style: italic }   H2.cjk { font-family: "MS Mincho"; font-size: 14pt; font-style: italic }   H2.ctl { font-family: "Tahoma"; font-size: 14pt; font-style: italic }  --&gt;  &lt;/style&gt;  &lt;h1 style="font-family: courier new;" class="western"&gt;Ruby on Rails&lt;/h1&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;This file contains brief descriptions of a Ruby on Rails project.&lt;/span&gt;&lt;/p&gt; &lt;h2 style="font-family: courier new;" class="western"&gt;Important Rails Commands&lt;/h2&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;Here a list of the most relevant rails command-line programs organized by task:&lt;/span&gt;&lt;/p&gt; &lt;ul  style="font-family:courier new;"&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;Starting  a Rails Project:&lt;/u&gt; &lt;span style="text-decoration: none;"&gt;rails  &lt;application&gt;&lt;/application&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;Executing  a Rails Project:&lt;/u&gt;&lt;span style="text-decoration: none;"&gt; ruby  script\server ( on application directory )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;Generating  a new Model:&lt;/u&gt;&lt;span style="text-decoration: none;"&gt; ruby  script\generate model &lt;model&gt;&lt;/model&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;Generating  a new Controller:&lt;/u&gt;&lt;span style="text-decoration: none;"&gt; ruby  script\generate controller &lt;controller&gt;&lt;/controller&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;h2 style="font-family: courier new;" class="western"&gt;Directory Contents&lt;/h2&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;app&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;Holds all the code that's specific to this particular application.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;app/controllers&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;Holds controllers that should be named like weblogs_controller.rb for automated URL mapping. All controllers should descend from ApplicationController which itself descends from ActionController::Base.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;app/models&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;Holds models that should be named like post.rb.&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;Most models will descend from ActiveRecord::Base.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;app/views&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;Holds the template files for the view that should be named like weblogs/index.erb for the WeblogsController#index action. All views use eRuby syntax.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;app/views/layouts&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;Holds the template files for layouts to be used with views. This models the common header/footer method of wrapping views. In your views, define a layout using the &lt;tt&gt;layout :default&lt;/tt&gt; and create a file named default.erb. Inside default.erb, call &lt;% yield %&gt; to render the view using this layout.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;app/helpers&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;Holds view helpers that should be named like weblogs_helper.rb. These are generated for you automatically when using script/generate for controllers. Helpers can be used to wrap functionality for your views into methods.&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;config&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;Configuration files for the Rails environment, the routing map, the database, and other dependencies.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;db&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;Contains the database schema in schema.rb. db/migrate contains all the sequence of Migrations for your schema.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;doc&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;This directory is where your application documentation will be stored when generated using &lt;tt&gt;rake doc:app&lt;/tt&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;lib&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;Application specific libraries. Basically, any kind of custom code that doesn't belong under controllers, models, or helpers. This directory is in the load path.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;public&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;The directory available for the web server. Contains subdirectories for images, stylesheets, and javascripts. Also contains the dispatchers and the default HTML files. This should be set as the DOCUMENT_ROOT of your web server.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;b&gt;script&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;Helper scripts for automation and generation.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;test&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;Unit and functional tests along with fixtures. When using the script/generate scripts, template test files will be generated for you and placed in this directory.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;vendor&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;" lang="en-US"&gt;  &lt;span style="font-size:85%;"&gt;External libraries that the application depends on. Also includes the plugins subdirectory. This directory is in the load path.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;h2 style="font-family: courier new;" class="western"&gt;How does Model, View and Controller relate to each other ?&lt;/h2&gt; &lt;p  style="font-family:courier new;"&gt;T&lt;span style="font-size:85%;"&gt;he application directory is structured like below:&lt;/span&gt;&lt;/p&gt; &lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;app&lt;/span&gt;&lt;/p&gt; &lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;|-controllers&lt;/span&gt;&lt;/p&gt; &lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;|-models&lt;/span&gt;&lt;/p&gt;  &lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;|-views&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;The fastest way to generate a complete crud for a model is to generate a controller with the scaffold option:&lt;/span&gt;&lt;/p&gt;  &lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;&gt; script/generate scaffold blog title:string content:text date_created:datetime&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;After understanding of ruby-on-rails it is considered better practice to generate models, views and controllers separately:&lt;/span&gt;&lt;/p&gt; &lt;ul  style="font-family:courier new;"&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;To  generate a blog controller, one must type:&lt;/span&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ul&gt;   &lt;p  style="margin-bottom: 0in;font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt; &gt; script/generate controller blog&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;   &lt;p  style="margin-bottom: 0in;font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="text-decoration: none;"&gt; &lt;/span&gt;&lt;u&gt;Result:&lt;/u&gt; a BlogController class will be generated at app/controllers in BlogController.rb&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;ul  style="font-family:courier new;"&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;To  generate a blog model, one must type:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ul&gt;   &lt;p  style="margin-bottom: 0in;font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt; &gt; script/generate model blog&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt; &lt;u&gt;Result&lt;/u&gt;: a Blog class will be generated at app/model in blog.rb&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;ul  style="font-family:courier new;"&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;views  can not be generated, you have to go to app/views/blog and create a  blog.html.erb.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ul&gt;   &lt;p  style="margin-bottom: 0in;font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;Views for BlogController are automatically assigned in app/views/blog by name convention. ( Since &lt;b&gt;Blog&lt;/b&gt;Controller will have a &lt;b&gt;blog&lt;/b&gt; directory in app/views ).&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0in;font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;Views in app/views/blog, must have a &lt;b&gt;*.html.erb&lt;/b&gt; extension and an &lt;b&gt;index.html.erb&lt;/b&gt; must be created for initial page. Other auxiliary pages can be created in the same directory with different names.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p face="courier new" style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;In order to add/remove/update models fields, one must only update the corresponding table in the data model only. After that the following command should be executed to update the models in Ruby-on-Rails:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in; font-family: courier new;"&gt;&lt;span style="font-size:85%;"&gt;&gt; rake db:migrate&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-7269830269714291107?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/OIUn7XVRCfdEm47z6eTlsHJ-JPg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OIUn7XVRCfdEm47z6eTlsHJ-JPg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/OIUn7XVRCfdEm47z6eTlsHJ-JPg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OIUn7XVRCfdEm47z6eTlsHJ-JPg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/OTSop5jqKFI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/7269830269714291107/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=7269830269714291107" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/7269830269714291107?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/7269830269714291107?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/OTSop5jqKFI/extremely-short-introduction-for-ruby.html" title="Extremely Short Introduction for Ruby on Rails" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2008/12/extremely-short-introduction-for-ruby.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0YFQnYzcSp7ImA9WxRUFEo.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-3199115922224119201</id><published>2008-11-23T12:10:00.001-08:00</published><updated>2008-11-23T14:25:13.889-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-23T14:25:13.889-08:00</app:edited><title>Generating Software Documentation from Unit Tests</title><content type="html">In the beginning of my career as a software developer I participated in two software projects with the traditional approach of document-first and code later. It didn't take too much time for me to realize this was a not a good aproach. We passed months capturing requirements and writing use cases just to find later that many use cases was actually different from what the stakeholders needed and many requirements have changed.&lt;br /&gt;&lt;br /&gt;Then I came across with agile software development.  The idea behind made perfect sense for me and some work colleagues and we started to introduce slowly this new paradigm in our department. Projects that lasted 1 year  ( yes ! 1 year ) or more now lasted only a couple of months. Besides that because we were demonstrating the software every week or two to the stakeholders and thus we had feedback often from them.&lt;br /&gt;This made us more productive and the final product (the software!) gained more quality and more confidence. But what happened to our business documentation ? We didn't drop a line of it.&lt;br /&gt;&lt;br /&gt;Many agilists advocate that agile software development is about absence of documentation. Recently many agilists say it is not removing documentation but that it is seen from a different perspective from document-oriented traditional approach.  Only the real necessary documentation is produced. Although it sounds perfectly reasonable we still need a way to document business rules for the IT sector managers and also stakeholders. They couldn't read and understand these rules directly from the source-code since they were not programmers or technicians.  So I started to think of a way to  automatically generate this documentation.&lt;br /&gt;&lt;br /&gt;I was talking to Anselmo from Siemens and he gave me an interesting idea: Automatic generation of business documentation from unit tests. I started thinking how could I implement this alternative in our software architecture model where we have a service class for each use case and I got to the idea below:&lt;br /&gt;&lt;br /&gt;For a Client Registration use case we could have the following unit tests:&lt;br /&gt;&lt;pre&gt;[TestFixture][BusinessRules] // Business rule attribute means this test must be documented&lt;br /&gt;class Client_Registration_Use_Case&lt;br /&gt;{ &lt;br /&gt;   [Test]&lt;br /&gt;   void Normal_Flow__Check_if_name_is_not_null() { ... }&lt;br /&gt;&lt;br /&gt;   [Test]&lt;br /&gt;   void Normal_Flow__Check_if_address_is_valid() { ... }&lt;br /&gt;&lt;br /&gt;   [Test]&lt;br /&gt;   void Normal_Flow__Check_if_there_is_another_client_with_same_name() { ... }&lt;br /&gt;&lt;br /&gt;   [Test]&lt;br /&gt;   void Normal_Flow__Save_New_Client() { ... }&lt;br /&gt;&lt;br /&gt;   [Test ExpectedException(typeof(NullClientNameException)) ]&lt;br /&gt;   void Alternative_Flow__If_client_name_is_null_raise_message_to_the_user() { ... }&lt;br /&gt;&lt;br /&gt;   [Test ExpectedException(typeof(InvalidClientAddressException)) ]&lt;br /&gt;   void Alternative_Flow__If_client_address_is_invalid_raise_message_to_the_user() { ... }&lt;br /&gt;&lt;br /&gt;   [Test ExpectedException(typeof(ClientNameAlreadyExistsException)) ]&lt;br /&gt;   void Alternative_Flow__If_another_client_with_the_same_name_was_found_raise_message_to_the_user() { ... }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;At the end, a script in the continuous integration process can read this file or assembly and transform very easily this information and save to a documentation file such as Docbook, ODT or Word Doc.  It is important to note that test methods should be placed in the right order so that the right documentation can be generated.  The only work is reading the class and methods names and generate the documentation as follows:&lt;br /&gt;&lt;br /&gt;-----------------------------------------------------------------&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Client Registration Use Case:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Normal Flow:&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Check if name is not null&lt;/li&gt;&lt;li&gt;Check if address is valid&lt;/li&gt;&lt;li&gt;Check if there is another client with same name&lt;/li&gt;&lt;li&gt;Save New Client&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span style="font-style: italic;"&gt;Alternate Flows:&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;If client name is null raise message to the user&lt;/li&gt;&lt;li&gt;If client address is invalid  raise message to the user&lt;/li&gt;&lt;li&gt;If another client with the same name was found  raise message to the user&lt;/li&gt;&lt;/ol&gt;-----------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;This idea has the following advantages:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Documentation reflects exactly what was implemented in the software code and never gets outdated&lt;/li&gt;&lt;li&gt;If a new check or action is needed in a use case documentation, the implementation and NOT documentation is changed&lt;/li&gt;&lt;li&gt;In order to update the documentation, new unit tests are required what can force discipline among the programmers&lt;/li&gt;&lt;li&gt;Every time a release is generated the entire application documentation is updated since the proper unit tests are written&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;There disadvantages as well:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Unit tests become more verbose what can slow down its implementation a little bit&lt;/li&gt;&lt;li&gt;Test methods descriptions may not reflect the test performed inside&lt;/li&gt;&lt;/ul&gt;However I still believe the benefits are higher and I wonder if someone is not applying this idea since it sounds so simple. If you have any ideas for agile business documentation please get in touch with me.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-3199115922224119201?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3KMacnSmPg4M1udXsCyGDKSRzzw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3KMacnSmPg4M1udXsCyGDKSRzzw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3KMacnSmPg4M1udXsCyGDKSRzzw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3KMacnSmPg4M1udXsCyGDKSRzzw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/6GN2EOnZ0pE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/3199115922224119201/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=3199115922224119201" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/3199115922224119201?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/3199115922224119201?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/6GN2EOnZ0pE/generating-software-documentation-from.html" title="Generating Software Documentation from Unit Tests" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2008/11/generating-software-documentation-from.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0ACRX05fip7ImA9WxRWFUg.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-2797623192274041419</id><published>2008-08-19T19:29:00.000-07:00</published><updated>2008-11-01T09:09:24.326-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-01T09:09:24.326-07:00</app:edited><title>Efficient Software Development Process with Open-Source Tools for .NET</title><content type="html">When a software is been built, a series of characteristics must be pursuit in order to deliver a quality product during the development process:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Agility&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Testability&lt;/li&gt;&lt;li&gt;Readability&lt;/li&gt;&lt;li&gt;Extensibility&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Automated Documentation&lt;/li&gt;&lt;/ul&gt;It it important to say that I presume many readers of this text are already convinced about the advantages brought by object oriented programming when compared to traditional development and the tools presented below support this kind of programming paradigm besides the goals specified above.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Object-Relational Mapping Tool: Castle Project Active Record&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;One of the most time-consuming things in software development is mapping classes in tables.&lt;br /&gt;This process is partially automated by tools such as NHibernate but the Active Record offered by Castle Project not only maps classes to tables but it is also capable to generate the database from the object model which confers agility to the software process.&lt;br /&gt;&lt;a href="http://www.castleproject.org/activerecord/index.html"&gt;http://www.castleproject.org/activerecord/index.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Source-Code Standards: FXCop&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Although it is free, FXCop is not a free-software since its code is private owned by Microsoft.&lt;br /&gt;Anyway it is very a useful tool whose objective is to verify if quality metrics and/or naming conventions of a project are been followed appropriately by the team members.&lt;br /&gt;By using naming well defined and known programming conventions, code readability is enhanced and different projects can be understood by every programmer in a software company.&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb429476%28VS.80%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Unit Tests: NUnit&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;It is the most used automated testing tool for .NET . These tests play an important role in a software project since they bring more confidence to developers to change software when needed since they can point out when a certain piece of the software might be broken due to some modification. Obviously NUnit brings testability to the software development environment.&lt;br /&gt;&lt;a href="http://www.nunit.org/index.php"&gt;http://www.nunit.org/index.php&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Test Coverage: PartCover&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;How can you know what parts of your code is being covered by automated tests ?&lt;br /&gt;This process is called test coverage and it is the objective of PartCover.&lt;br /&gt;Altough NCover is largely mentioned in the net, PartCover is becoming increasingly&lt;br /&gt;important as a test coverage open-source project.&lt;br /&gt;&lt;a href="http://sourceforge.net/projects/partcover/"&gt;http://sourceforge.net/projects/partcover/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Automated Documentation: NDoc&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Documentation can be a time consuming task but without it, the software extensibility and maintainability can slow down considerably specially for people outside the project and unaware of coding practices. One of the fastest ways to get documentation is generating it from the source-code. NDoc can generate developer level documentation from the XML tags in the C# source-code.&lt;br /&gt;&lt;a title="http://ndoc.sourceforge.net" href="http://ndoc.sourceforge.net/" id="mmns"&gt;http://ndoc.sourceforge.net&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Web Framework: MonoRail&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The Castle Project seems to understand what is to have an agile development. Having this in mind, MonoRail is a web framework that truly obeys the MVC Design Pattern without slowing developers down. Besides agile, this framework lets us to have an improved readability also compared to traditional ASP.NET programming.&lt;br /&gt;&lt;a href="http://www.castleproject.org/monorail/gettingstarted/index.html"&gt;http://www.castleproject.org/monorail/gettingstarted/index.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Continuous Integration: Cruise Control .NET&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Prior sections some tools for software quality were presented such as FXCop, NUnit, PartCover and NDoc. Although useful it is very easy for one of the team members to forget to manually execute some of this tools during the development process. Remembering and executing these tools can also be error prone since some member of the team can forget to execute some of these tools.&lt;br /&gt;In order to overcome these drawbacks and others, continuous integration rised as one the most known practices from Extreme Programming (XP). ( See XP in &lt;a title="http://www.extremeprogramming.org/" href="http://www.extremeprogramming.org/" id="uhsj"&gt;http://www.extremeprogramming.org/&lt;/a&gt; )&lt;br /&gt;Basically continuous integration is performed by a build tool such as Cruise Control ( &lt;a title="http://cruisecontrol.sourceforge.net/" href="http://cruisecontrol.sourceforge.net/" id="d0m_"&gt;http://cruisecontrol.sourceforge.net/&lt;/a&gt; ) that is responsible for executing specified tasks necessary prior to software delivery to the users such as compilation checking, unit tests executing, quality metrics verification and finally publication. However another combination of tasks can be though such as email notification and many others.&lt;br /&gt;Generally the continuous integration process is executed manually or during the night when there is low activity but it is possible to trigger this process through a version control system such as SVN prior to accept a commit requested by a team programmer.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-2797623192274041419?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/QGdtaEhYUl-dQOniwyY5D6hL4is/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QGdtaEhYUl-dQOniwyY5D6hL4is/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/QGdtaEhYUl-dQOniwyY5D6hL4is/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QGdtaEhYUl-dQOniwyY5D6hL4is/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/KTcOjwm4zL4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/2797623192274041419/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=2797623192274041419" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/2797623192274041419?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/2797623192274041419?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/KTcOjwm4zL4/efficient-software-development-process.html" title="Efficient Software Development Process with Open-Source Tools for .NET" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2008/08/efficient-software-development-process.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUAFRHcyeyp7ImA9WxdbFko.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-4159735445163389141</id><published>2008-07-24T18:41:00.000-07:00</published><updated>2008-08-13T17:28:35.993-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-08-13T17:28:35.993-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Scrum Venture Capital Jeff Sutherland" /><title>Scrum as a criteria for Venture Capital Groups</title><content type="html">I just read a Foreword from Jeff Sutherland ( co-creator of Scrum ) from the book "Scrum and XP from the Trenches" where he comments how he chooses companies who really apply Scrum framework ( an agile framework or methodology to develop software ) for a venture capital group as an agile coach.&lt;br /&gt;&lt;br /&gt;The more time pass the more I realize how agile software development will play an important role in near future. It already plays an important role but it can become a requirement for startup companies in search for funding from venture capital groups.&lt;br /&gt;&lt;br /&gt;If a company can not deliver its products in time or can not deliver working software or can not deliver something that was not what the client was expecting, it should not be expected that they would receive funding. As Mike Cohn cited in the same book in his foreword, agile development is not about beautiful documentation or future-problem-proof code, it is about software done and working. And that's exactly what clients need and expect from a software company.&lt;br /&gt;At the same time, Scrum as well as other kinds of agile software ideas ( be it frameworks, methodologies or practices ) is very easy to put in practice. Any company or organization can start using this idea anytime they want.&lt;br /&gt;&lt;br /&gt;If you have an idea about how is the Scrum process in five minutes or so, take a look at this articles: &lt;a href="http://www.softhouse.se/Uploades/Scrum_eng_webb.pdf"&gt;http://www.softhouse.se/Uploades/Scrum_eng_webb.pdf&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Addionally the book "Scrum and XP from the Trenches" mentioned in the beginning of this post can be downloaded here: &lt;a href="http://www.infoq.com/minibooks/scrum-xp-from-the-trenches"&gt;http://www.infoq.com/minibooks/scrum-xp-from-the-trenches&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Personally, as a software developer and a small investor I will take Jeff's tip for future investments in tech companies.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-4159735445163389141?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TZpL0AYjflPz7Ov3ECXd-nacuAk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TZpL0AYjflPz7Ov3ECXd-nacuAk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TZpL0AYjflPz7Ov3ECXd-nacuAk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TZpL0AYjflPz7Ov3ECXd-nacuAk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/WKkh5NyyelY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/4159735445163389141/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=4159735445163389141" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/4159735445163389141?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/4159735445163389141?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/WKkh5NyyelY/scrum-as-criteria-for-venture-capital.html" title="Scrum as a criteria for Venture Capital Groups" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2008/07/scrum-as-criteria-for-venture-capital.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0ECSH0yfCp7ImA9WxdVFEo.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-6123779872367707664</id><published>2008-07-18T22:57:00.000-07:00</published><updated>2008-07-19T06:54:29.394-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-07-19T06:54:29.394-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="NHibernate XML Remember .NET" /><title>5 Things You Should Remember about NHibernate</title><content type="html">NHibernate is probably the most used ORM (object-relational mapping tool) for .NET applications and it is based in Hibernate the most used ORM in Java for years. &lt;br /&gt;The learning curve to start working with NHibernate can be reduced if you remember the take the following steps:&lt;br /&gt;&lt;br /&gt;1) The domain class should have at least one &lt;span style="font-weight: bold;"&gt;public&lt;/span&gt; or &lt;span style="font-weight: bold;"&gt;protected&lt;/span&gt; &lt;span style="font-weight: bold;"&gt;parameterless&lt;/span&gt; &lt;span style="font-weight: bold;"&gt;constructor&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;2) The domain classes' public properties and methods must declared with the &lt;span style="font-weight: bold;"&gt;virtual&lt;/span&gt; reserved word&lt;br /&gt;&lt;br /&gt;3) For XML mappings,  remember to rename your mapping files ending with &lt;span style="font-weight: bold;"&gt;*.hbm.xml&lt;/span&gt; not only &lt;span style="font-weight: bold;"&gt;*.xml&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;4) Also for XML mappings, remember to set the property of each file to &lt;span style="font-weight: bold;"&gt;embedded resource&lt;/span&gt; instead of content&lt;br /&gt;&lt;br /&gt;5) Avoid using&lt;span style="font-weight: bold;"&gt; composite-id's&lt;/span&gt; classes as much as you can since they don't work very well when used in cascade collections and they make development more difficult&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-6123779872367707664?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/b3yuJ45H6Jewtmq4wkROnHcUoyk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/b3yuJ45H6Jewtmq4wkROnHcUoyk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/b3yuJ45H6Jewtmq4wkROnHcUoyk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/b3yuJ45H6Jewtmq4wkROnHcUoyk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/7pTz0xPk-8g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/6123779872367707664/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=6123779872367707664" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/6123779872367707664?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/6123779872367707664?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/7pTz0xPk-8g/5-things-you-should-remember-about.html" title="5 Things You Should Remember about NHibernate" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2008/07/5-things-you-should-remember-about.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUIHQnczeip7ImA9WxdVFEo.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-7768937267897008586</id><published>2008-07-18T22:41:00.000-07:00</published><updated>2008-07-19T06:18:53.982-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-07-19T06:18:53.982-07:00</app:edited><title>Unit Tests Rule Software Development</title><content type="html">Even after a relatively long time using object oriented systems we still couldn't deal well with a growing problem. The lack of automated tests.&lt;br /&gt;&lt;br /&gt;The absence of unit tests reduce the programmers confidence about the system and makes it very difficult if not impossible to modify the source-code.  Since each modification can cause a lot of other bugs and undesired side-effects in other parts of the system or in other systems, the system can not evolve with the changing business rules and the changing technological knowledge.&lt;br /&gt;&lt;br /&gt;Well that was true some months ago, now we are building a lot of unit tests for the systems already in production. Ironically due to  some good architectural choices such as persistence isolation and POCO objects, it was not difficult to start testing with the Stub technique. It was all there, we just started creating test cases.&lt;br /&gt;&lt;br /&gt;In reality, although not the ideal way, a set of use-case tests are being implemented in order to assure the right execution of what was working before. So the service layer is tested not the business objects at this time.&lt;br /&gt;&lt;br /&gt;Now we are looking for automated ways to create mode real test cases in other to produce all the tests we need as fast as we can. Perhaps a testing framework will be necessary.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-7768937267897008586?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/O_GqI0OTJ7vADk6ljtrHt_BRr6Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/O_GqI0OTJ7vADk6ljtrHt_BRr6Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/O_GqI0OTJ7vADk6ljtrHt_BRr6Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/O_GqI0OTJ7vADk6ljtrHt_BRr6Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/WZtHNvlIQXc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/7768937267897008586/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=7768937267897008586" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/7768937267897008586?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/7768937267897008586?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/WZtHNvlIQXc/unit-tests-rule-software-development.html" title="Unit Tests Rule Software Development" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2008/07/unit-tests-rule-software-development.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0EHQ3Y8eSp7ImA9WxFTEUo.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-4858374068583043240</id><published>2008-03-19T19:25:00.000-07:00</published><updated>2010-04-01T19:33:52.871-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-01T19:33:52.871-07:00</app:edited><title>Rich Domain Objects</title><content type="html">In object oriented programming, domain objects are the key of the software development. However, many programmers tend to write these classes as simple get/set storage just like the example below in pseudo-code:&lt;br /&gt;
&lt;pre class="brush: csharp;gutter=false"&gt;class Client
{
private long id;
public string Id
{
get { return this.id; }
set { this.id = value }
}
private string name;
public string Name
{
get {return this.name; }
set { this.name = value; }
}

private int registrationYear;
public int RegistrationYear
{
get { return this.registrationyear; }
set { registrationYear = value; }
}
}
&lt;/pre&gt;&lt;br /&gt;
The instances of the class above are the so-called anemic-objects. These objects don't verify their internal state and their behavior and thus accept any value as input.&lt;br /&gt;
As a consequence the extra-work is delegated to the application.&lt;br /&gt;
&lt;br /&gt;
However these objects are not very practical for complex domain models and they don't take full power of the object programming. Classes not only carry data but also a functional part which are exactly the methods and properties.&lt;br /&gt;
&lt;br /&gt;
To attack complex domains there are rich domain objects which are objects capable of verifying all these aspects internally preventing the programmers from having to remember them later at the time of building the application.&lt;br /&gt;
&lt;br /&gt;
Rich domain objects help other developers not familiar with the business rules on how to create an application for that particular domain.&lt;br /&gt;
&lt;br /&gt;
In order to work efficiently with rich domain objects the following design rules can be adopted:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Constructors should contain required parameters to create a new instance for the class from the business point of view&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="brush: csharp;gutter=false"&gt;// Rule 1 - Constructor with mandatory parameters
public Client(name,registrationDate) {...}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Always use properties instead of accessing fields directly to read or modify data in the class implementation except obviously in the properties implementations&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;// Rule 2 - Use properties instead of fields
{ this.Name = name; this.RegistrationDate = registrationDate; }
&lt;/pre&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Set parameters should check the input parameters appropriately and check the objects internal state before altering the object according to the domain rules&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="brush: csharp;gutter=false"&gt;public string Name
{
get {return this.name; }
// Rule 3 - Set property checks the input value
set { if (value == "") throw new SystemException("Empty name is invalid");
this.name = value; }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Get parameters should check the object internal state before returning a value&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public int RegistrationYear
{
//Rule 4-Get property checks object and application state before returning a value
get
{
if (User.CurrentUser().IsManager())
return this.registrationYear;
else
throw new SystemException("No permission for Client's Registration Year.");
}
set
{
if ((value &amp;lt;&amp;gt; DateTime.now.year))
throw new SystemException("Year must be from 1980 until now");
this.registrationYear = value; }
}
}
&lt;/pre&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Classes should be designed in order to follow primarily the business model and then the data model&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Following this rules a Client class could be:&lt;br /&gt;
&lt;pre class="brush: csharp;gutter=false"&gt;// Rule 5 - Client Class is designed according to the business model
class Client
{
// Rule 1 - Constructor with mandatory parameters
public Client(name,registrationDate)
// Rule 2 - Use properties instead of fields
{ this.Name = name; this.RegistrationDate = registrationDate; }

private string id;
public string Id
{
get { return this.id; }
set { this.id = value; }
}

private string name;
public string Name
{
get {return this.name; }
// Rule 3 - Set property checks the input value
set
{
if (value == "") throw new SystemException("Empty name is invalid");
this.name = value;
}
}

private int registrationYear;
public int RegistrationYear
// Rule 4-Get property checks object and application state before returning a value
{
get
{
if (User.CurrentUser().IsManager())
return this.registrationYear;
else
throw new SystemException("No permission for Client's Registration Year.");
}
set
{
if ((value != DateTime.now.year))
throw new SystemException("Year must be from 1980 until now");
this.registrationYear = value;
}
}
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-4858374068583043240?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/QQPbbDvHxTlDDRBOpcpwkJSeyfM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QQPbbDvHxTlDDRBOpcpwkJSeyfM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/QQPbbDvHxTlDDRBOpcpwkJSeyfM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QQPbbDvHxTlDDRBOpcpwkJSeyfM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/_-AIz3VAd2o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/4858374068583043240/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=4858374068583043240" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/4858374068583043240?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/4858374068583043240?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/_-AIz3VAd2o/rich-domain-objects.html" title="Rich Domain Objects" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>2</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2008/03/rich-domain-objects.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUYFQXY8fip7ImA9WxdVFEo.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-5044463006345782344</id><published>2007-12-20T15:28:00.000-08:00</published><updated>2008-07-19T06:11:50.876-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-07-19T06:11:50.876-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Exception Exceptions  Java .NET Best Practice" /><title>Best Practice to Handle Exceptions</title><content type="html">Modern programming languages come with try/catch/finally blocks and many times an Exception Hierarchy of classes is provided also.&lt;br /&gt;Exceptions are a powerful tool that can be used to handle both system and user errors.&lt;br /&gt;When exceptions are thrown in some part of the code, the system keeps popping ( removing the head ) of the stack until it finds a catch statement that can handle that exception type.&lt;br /&gt;One common way to capture exceptions is to write several catches from the most specific to the most generic exception class until you can capture the exception type appropriately according to its type.&lt;br /&gt;Check code below:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;  // code block&lt;br /&gt;}&lt;br /&gt;catch ( SpecialSystemException e)&lt;br /&gt;{&lt;br /&gt;  // code to handle SpecialSystemException  &lt;br /&gt;}&lt;br /&gt;catch ( SystemException e)&lt;br /&gt;{&lt;br /&gt;  // code to handle SystemException&lt;br /&gt;}&lt;br /&gt;catch ( Exception e)&lt;br /&gt;{&lt;br /&gt;  // code to handle Exception&lt;br /&gt;}&lt;br /&gt;finally&lt;br /&gt;{&lt;br /&gt;  // finishes code block&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;However in many cases it is desired to treat each exception same way according to its type in the entire system. In this case the code template shown above has some disadvantages:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Programmers must write more code to implement try/catch/finally code blocks to due the several "catch" statements for each exception type that is intended to treat&lt;/li&gt;&lt;li&gt;Code to treat exception classes are replicated in the software code&lt;br /&gt;&lt;/li&gt;&lt;li&gt;And finally if it demands more work and it is repeated than it is error prone&lt;/li&gt;&lt;/ul&gt;In order to solve this problem a better approach is to create a separate centralized class to treat all exceptions thrown from the system internally. Like the .NET pseudo-code example below:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class ExceptionHandler&lt;br /&gt;{&lt;br /&gt;  public static void Handler(Exception exception)&lt;br /&gt;  {&lt;br /&gt;    if (exception.GetType() == typeof(SpecialSystemException))&lt;br /&gt;    {&lt;br /&gt;      // Code that deals with SpecialSystemException &lt;br /&gt;    }   &lt;br /&gt;    else if (exception.GetType() == typeof(SystemException))&lt;br /&gt;    { &lt;br /&gt;      // Code that deals with SystemException&lt;br /&gt;    }&lt;br /&gt;  else if (exeception.GetType() == typeof(Exception))&lt;br /&gt;  {&lt;br /&gt;      // Code that deals with Exception&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Replacing the code of the first example:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;  // code block&lt;br /&gt;}&lt;br /&gt;catch ( Exception e)&lt;br /&gt;{&lt;br /&gt;  // Exceptions are now treated internally by the method below&lt;br /&gt;  ExceptionHandler.Handler(exception);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-5044463006345782344?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/91FbVnIpY4Nu6q7GMnOdXuBo1rQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/91FbVnIpY4Nu6q7GMnOdXuBo1rQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/91FbVnIpY4Nu6q7GMnOdXuBo1rQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/91FbVnIpY4Nu6q7GMnOdXuBo1rQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/nLqLJpdFylE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/5044463006345782344/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=5044463006345782344" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/5044463006345782344?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/5044463006345782344?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/nLqLJpdFylE/best-practice-to-handle-exceptions.html" title="Best Practice to Handle Exceptions" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2007/12/best-practice-to-handle-exceptions.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUAQ3k_eCp7ImA9WxdaEUQ.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-2823379130169424845</id><published>2007-12-03T15:36:00.000-08:00</published><updated>2008-08-19T19:10:42.740-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-08-19T19:10:42.740-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="database model entity primary key development" /><title>Choosing the Right Primary Keys</title><content type="html">One of the most common data modeling is the use of composite keys and natural keys as primary keys to identify tables in the database.&lt;br /&gt;Composite-key tables use more than one key to identify a row while natural keys use domain information to identify a row such as Social Security Number to identify a Person. In most cases a composite-key is actually a composite-natural-key.&lt;br /&gt;&lt;br /&gt;However these tecniques are not consider good practices to choose the table primary keys due to the following factors:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Business Rules change over time but primary keys don't&lt;br /&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Business rules are dynamic but primary keys are static until you update the database model what can cost a lot time and effort if not impossible. For example if you identify a Client with a Social Security number you may not be able to identify a foreign Person if needed or maybe the government can decide to use the same Social Security Number for more than one person. This lack of capacity to change the database model can reduce significantly the agility of an organization to adapt its business model to new kind of reality what reduces its capacity to compete with other organizations.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;i&gt;Figure 1 - Table identified by a natural key&lt;/i&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id="y4sa" style="padding: 1em 0pt; text-align: center;"&gt;&lt;div id="hb0m" style="padding: 1em 0pt; text-align: center;"&gt;&lt;img style="width: 186px; height: 89px;" src="http://docs.google.com/File?id=dd9jw5vs_97pv77k6g7" /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Composite Keys require more work&lt;/li&gt;&lt;ul&gt;&lt;li&gt;It is necessary to write longer SQL queries since you have to use all the primary keys to join this table to another one.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;select cli.name, pd.description, sa.date, sa.quantity&lt;br /&gt;from Client cli&lt;br /&gt;inner join Sales sa on&lt;br /&gt;( cli.socialSecurityNumber = sa.socialSecurityNumber )&lt;br /&gt;inner join Product pd on&lt;br /&gt;( sa.idProductType = pd.idProductType and&lt;br /&gt;sa.vendorRegistration = pd.vendorRegistration )&lt;br /&gt;where sa.date &gt;= '2007-12-01'&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Make the Database model less readable&lt;/li&gt;&lt;ul&gt;&lt;li&gt; Composite keys spread to other tables as a foreign key and are added to other foreign composite-key columns. In some cases where composite-keys are widely used there are much more composite-key columns in a table than useful information.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;i&gt;Figure 2 - Only date and quantity are Sales columns&lt;/i&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;i&gt; the rest are inherited primakey keys from other tables&lt;/i&gt;&lt;/div&gt;&lt;div id="j-f6" style="padding: 1em 0pt; text-align: center;"&gt;&lt;img style="width: 215px; height: 121px;" src="http://docs.google.com/File?id=dd9jw5vs_96dsqwdwgk" /&gt;&lt;br /&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;In the other hand one of the stronger arguments in favor of composite and natural-keys is that they provide a safer way to restrict data integrity avoiding certain columns in a table to repeat while with a single primary key can not garantee this.&lt;br /&gt;But many people forget that this data integrity can be done in single-primary tables too by using alternate keys. With alternate keys you can choose a group of columns in a table make them unique just like a composite-key would do it.&lt;br /&gt;&lt;br /&gt;In order to present this idea in more details below there are two examples, one with the traditional composite-key and natural keys aproach and the other with the proposed idea of using single primaty keys ( non-natural keys ) and alternate keys.&lt;br /&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;div style="text-align: center;"&gt;&lt;i&gt;Figure 3- Data model example that makes use of natural-keys&lt;/i&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;img style="width: 555px; height: 339px;" src="http://docs.google.com/File?id=dd9jw5vs_98cnzjw7hp" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Figure 4 - Data model example with single primary keys and alternate keys&lt;/span&gt;&lt;br /&gt;&lt;div id="h0gu" style="padding: 1em 0pt; text-align: center;"&gt;&lt;img style="width: 555px; height: 335px;" src="http://docs.google.com/File?id=dd9jw5vs_99c49jxdgw" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-2823379130169424845?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/X-g88dBYlHrZ4f6BHhryTvkBmcM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/X-g88dBYlHrZ4f6BHhryTvkBmcM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/X-g88dBYlHrZ4f6BHhryTvkBmcM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/X-g88dBYlHrZ4f6BHhryTvkBmcM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/v2mDa_CI6vw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/2823379130169424845/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=2823379130169424845" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/2823379130169424845?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/2823379130169424845?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/v2mDa_CI6vw/choosing-right-primary-keys.html" title="Choosing the Right Primary Keys" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2007/12/choosing-right-primary-keys.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUcHQnsyfCp7ImA9WxdVFEk.&quot;"><id>tag:blogger.com,1999:blog-36756501.post-8438604012371843500</id><published>2007-10-17T18:21:00.000-07:00</published><updated>2008-07-18T22:57:13.594-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-07-18T22:57:13.594-07:00</app:edited><title>Less is More - Dynamically typed languages</title><content type="html">When I was in the university I learned that strongly typed languages should be preferred since they avoid the programmers from using a certain variable in way that it was not meant to.&lt;br /&gt;If I declare "string name;" I know this will accept only strings and will prevent a programmer from assign a number or a boolean value on it.&lt;br /&gt;&lt;br /&gt;But this seems to be a false concern with the success of other languages such as Python and Ruby.&lt;br /&gt;This programming languages are now used to each time more complex software and nobody is complaining about their "dynamic" features.&lt;br /&gt;&lt;br /&gt;The goal the new development tools are trying to achieve is how can I do my software faster in a clean and organized way. Less is More !&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36756501-8438604012371843500?l=hcmarchezi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/e4AfVeUvZOUCKKPP-7RNKqmoWVI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/e4AfVeUvZOUCKKPP-7RNKqmoWVI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/e4AfVeUvZOUCKKPP-7RNKqmoWVI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/e4AfVeUvZOUCKKPP-7RNKqmoWVI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/OoSoftwareDevelopment/~4/oqJi5j74Do8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://hcmarchezi.blogspot.com/feeds/8438604012371843500/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=36756501&amp;postID=8438604012371843500" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/8438604012371843500?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/36756501/posts/default/8438604012371843500?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/OoSoftwareDevelopment/~3/oqJi5j74Do8/more-is-less-dynamically-typed.html" title="Less is More - Dynamically typed languages" /><author><name>H. C. Marchezi</name><uri>http://www.blogger.com/profile/00944577545488056873</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="17" height="32" src="http://bp1.blogger.com/_WHpubqoOAQY/R2sKy_BB2pI/AAAAAAAAAiM/hN0BYu0QK9U/S220/HCM_BODY.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://hcmarchezi.blogspot.com/2007/10/more-is-less-dynamically-typed.html</feedburner:origLink></entry></feed>

