<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>oop &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://wordpress.com/tag/oop/</link>
	<description>Feed of posts on WordPress.com tagged "oop"</description>
	<pubDate>Fri, 25 Jul 2008 23:02:09 +0000</pubDate>

	<generator>http://wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Enumerators in C# .NET]]></title>
<link>http://shiman.wordpress.com/?p=113</link>
<pubDate>Fri, 25 Jul 2008 18:49:36 +0000</pubDate>
<dc:creator>shiman</dc:creator>
<guid>http://shiman.wordpress.com/?p=113</guid>
<description><![CDATA[Enumerators are part of the enumeration pattern and normally implemented as a nested class within th]]></description>
<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0;"><span style="font-family:Arial;"><span style="font-size:small;">Enumerators are part of the enumeration pattern and normally implemented as a nested class within the collection type. The primary benefit of nested classes is access to the private members of the outer class. This access allows you to avoid breaking the rules of encapsulation to allow the enumerator class to access the data store of the collection. The data store is undoubtedly a private member of the collection class.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Arial;"><span style="font-size:small;">Enumerators implement the <em>IEnumerator</em> interface, which has three members. This is the <em>IEnumerator</em> interface:</span></span></p>
<table class="MsoTableGrid" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:6.15in;background-color:transparent;border:windowtext 1pt solid;padding:0 5.4pt;" width="590" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:Consolas;">public</span><span style="font-size:10pt;font-family:Consolas;"> <span style="color:blue;">interface</span> <span style="color:#2b91af;">IEnumerator</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span><span style="color:blue;">object</span> Current { <span style="color:blue;">get</span>; }</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span><span style="color:blue;">bool</span> MoveNext();</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span><span style="color:blue;">void</span> Reset();</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;">}</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Arial;"><span style="font-size:small;">The <em>Current</em> property returns the current element of the collection. <em>MoveNext</em> moves the <em>Current</em> property to the next element. If the iteration has completed, <em>MoveNext</em> returns <em>false</em>. Otherwise, <em>MoveNext</em> returns <em>true</em>. Notice that there is not a <em>MovePrevious</em> method; enumeration is forward only. The <em>Reset</em> method returns the enumeration to the beginning of the collection.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Arial;"><span style="font-size:small;">The enumerator is the state machine representing the enumeration. Part of the state machine is the cursor, which is the collection index or locator. The cursor is not necessarily an integral value, but normally it is. For a link list, the cursor may be a node, which is an object. When the enumerator is created, the cursor initially points before the first element of the collection. Do not access the <em>Current</em> property while the cursor is in this initial state. Call <em>MoveNext</em> first, which positions the cursor at the first element of the collection.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Arial;"><span style="font-size:small;">The following is a typical constructor of an enumerator. In this example, the constructor makes a snapshot of the collection. For reasons of simplicity, the collection is a basic array. The cursor is then set to –1, which is before the first element of the collection.</span></span></p>
<table class="MsoTableGrid" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:6.15in;background-color:transparent;border:windowtext 1pt solid;padding:0 5.4pt;" width="590" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:Consolas;">public</span><span style="font-size:10pt;font-family:Consolas;"> Enumerator(<span style="color:blue;">object</span>[] items) </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>   </span>elements = <span style="color:blue;">new</span> <span style="color:blue;">object</span>[items.Length];</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>   </span>Array.Copy(items, elements, items.Length);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>   </span>cursor=-1;</span></p>
<p class="para" style="margin:auto 0;"><span style="font-size:10pt;font-family:Consolas;">}</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Arial;"><span style="font-size:small;">The <em>MoveNext</em> method increments the value of the cursor. This action moves the <em>Current</em> property to the next element of the collection. If the list has been fully iterated, <em>MoveNext </em></span><a name="619"></a><a name="IDX-272"></a><span style="font-size:small;">returns <em>false</em>. Collections are not circular, where <em>MoveNext</em> might cycle through a collection. Circular collections are not within the enumerator pattern. The <em>Current</em> property is not valid after the collection has been fully enumerated. For this reason, do not use the <em>Current</em> property after <em>MoveNext</em> returns <em>false</em>.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Arial;"><span style="font-size:small;">Here is one possible implementation of the <em>MoveNext</em> method:</span></span></p>
<table class="MsoTableGrid" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:6.15in;background-color:transparent;border:windowtext 1pt solid;padding:0 5.4pt;" width="590" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:Consolas;">public</span><span style="font-size:10pt;font-family:Consolas;"> <span style="color:blue;">bool</span> MoveNext() </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>++cursor;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span><span style="color:blue;">if</span>(cursor&#62;(elements.Length-1)) </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:blue;">return</span> <span style="color:blue;">false</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span><span style="color:blue;">return</span> <span style="color:blue;">true</span>;</span></p>
<p class="para" style="margin:auto 0;"><span style="font-size:10pt;font-family:Consolas;">}</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Arial;"><span style="font-size:small;">The <em>Reset</em> method resets the enumeration. The cursor is updated to point to before the collection again. Resetting the cursor also automatically resets the <em>Current</em> property.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Arial;"><span style="font-size:small;">Here is a <em>Reset</em> method:</span></span></p>
<table class="MsoTableGrid" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:6.15in;background-color:transparent;border:windowtext 1pt solid;padding:0 5.4pt;" width="590" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:Consolas;">public</span><span style="font-size:10pt;font-family:Consolas;"> <span style="color:blue;">void</span> Reset()</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>cursor=-1;</span></p>
<p class="para" style="margin:auto 0;"><span style="font-size:10pt;font-family:Consolas;">}</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Arial;"><span style="font-size:small;">With the cursor as a reference to the current item, the <em>Current</em> property provides access to the current element of the collection. The <em>Current</em> property must be read-only. Implement the <em>get</em> method of the property but not the <em>set</em> method. The implementation should check for fence-post errors. If the index is before or after the collection, the appropriate exception should be thrown.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Arial;"><span style="font-size:small;">Here is an implementation of the <em>Current</em> property:</span></span></p>
<table class="MsoTableGrid" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:6.15in;background-color:transparent;border:windowtext 1pt solid;padding:0 5.4pt;" width="590" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:Consolas;">public</span><span style="font-size:10pt;font-family:Consolas;"> <span style="color:blue;">object</span> Current</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span><span style="color:blue;">get</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:blue;">if</span> (cursor &#62; (elements.Length - 1))</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span><span style="color:blue;">throw</span> <span style="color:blue;">new</span> <span style="color:#2b91af;">InvalidOperationException</span>(<span style="color:#a31515;">"Enumeration already finished"</span>);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:blue;">if</span> (cursor == -1)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span><span style="color:blue;">throw</span> <span style="color:blue;">new</span> <span style="color:#2b91af;">InvalidOperationException</span>(<span style="color:#a31515;">"Enumeration not started"</span>);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:blue;">return</span> elements[cursor];</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Consolas;">}</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Enumeration in C# .NET : Best Practices]]></title>
<link>http://shiman.wordpress.com/?p=110</link>
<pubDate>Thu, 24 Jul 2008 12:21:50 +0000</pubDate>
<dc:creator>shiman</dc:creator>
<guid>http://shiman.wordpress.com/?p=110</guid>
<description><![CDATA[Enumerable objects implement the IEnumerable interface. The GetEnumerator method is the only member ]]></description>
<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Enumerable objects implement the <em>IEnumerable</em> interface. The <em>GetEnumerator</em> method is the only member of this interface. It returns an enumerator, which is used to enumerate nongeneric collections.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">This is the <em>IEnumerable</em> interface:</span></p>
<table class="MsoTableGrid" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:6.65in;background-color:transparent;border:black 1pt solid;padding:0 5.4pt;" width="638" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:Consolas;">public</span><span style="font-size:10pt;font-family:Consolas;"> <span style="color:blue;">interface</span> <span style="color:#2b91af;">IEnumerable</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span><span style="color:#2b91af;">IEnumerator</span> GetEnumerator();</span></p>
<p class="para" style="margin:auto 0;"><span style="font-size:10pt;font-family:Consolas;">}</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Each invocation of the <em>GetEnumerator</em> method returns a unique enumerator. The enumerator is a state machine that minimally maintains a snapshot of the target collection and a cursor. The cursor points to the current item of the collection. The snapshot is a static copy of the collection. What happens if a collection is modified while being enumerated? An exception occurs. You could lock the collection during enumeration, but it might cause substantial performance degradation. As a best practice, an enumerator should capture the collection as a snapshot. This isolates the enumerator from changes to the original collection. In addition, </span><a name="617"></a><a name="IDX-271"></a><span style="font-size:small;font-family:Calibri;">the snapshot collection is read-only. The <em>GetEnumerator</em> method should be thread-safe, guaranteeing that a unique enumerator is returned, which references an isolated collection regardless of the thread context.</span></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Basic Object-Oriented Concepts ]]></title>
<link>http://vsreddy.wordpress.com/?p=73</link>
<pubDate>Thu, 24 Jul 2008 08:37:03 +0000</pubDate>
<dc:creator>Venkat Shiva Reddy</dc:creator>
<guid>http://vsreddy.wordpress.com/?p=73</guid>
<description><![CDATA[
How People Understand Technology 
How People Approach Object-Oriented Technology 
Object-Oriented T]]></description>
<content:encoded><![CDATA[<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">How People Understand Technology </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">How People Approach Object-Oriented Technology </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Object-Oriented Terms and Concepts </span></span>
<ul type="circle">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Objects </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Classes, Metaclasses, Parameterized Classes, and Exemplars </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Black Boxes and Interfaces </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Aggregation </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Specialization and Inheritance </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Abstract Classes </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Operations </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Constants </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Exceptions </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Object Coupling and Object Cohesion </span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Systems of Objects </span></span></li>
</ul>
</li>
</ul>
<h3 style="margin:auto 0;"><a name="hput"><span style="font-family:&#34;"><span style="font-size:medium;">How People Understand Technology</span></span></a><span style="font-family:&#34;"><span style="font-size:medium;"> </span></span></h3>
<h1 style="margin:auto 0;"><a name="hput"><span style="font-family:'Verdana','sans-serif';">How People Understand Technology</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<p><span style="font-family:&#34;"><span style="font-size:small;">There is an old story of how several blind men set out to understand what an elephant was by examining a live specimen. Each of them explored a different part of the elephant's body. One blind man, falling against the elephant's side, proclaimed that an elephant must be very much like a wall. Another, grasping the elephant's ear, decided that an elephant must closely resemble a leaf. One grabbed the elephant's tail and determined that elephants must resemble ropes. Yet another felt the elephant's leg and came away convinced that elephants are very much like trees. Still another held the elephant's trunk and exclaimed that elephants had much in common with snakes.</span></span></p>
<p style="text-align:center;" align="center"> <a href="http://vsreddy.wordpress.com/files/2008/07/pic11.png"><img class="aligncenter size-medium wp-image-74" src="http://vsreddy.wordpress.com/files/2008/07/pic11.png?w=300" alt="" width="300" height="161" /></a></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:&#34;"><span style="font-size:small;">While there was at least a grain of truth in each blind man's observation, none of them had a complete and accurate understanding of just what an elephant is. We can imagine the many animated debates that these blind men had when they compared notes -- each sure that the others must be wrong.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Often, people studying technology are like the blind men in our story. It is very common to focus intently on one facet of one aspect of a technology while ignoring the vast breadth of the same technology. There is nothing wrong with this -- unless a person studying the facet begins to think that he or she has somehow acquired a good grasp of the entire technology.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">To acquire an in-depth understanding of a technology requires a great deal of research. The sheer bulk of material that must be examined is daunting. The task is further complicated by the unfortunate errors contained in many discussions. Even if an individual can assimilate a large quantity of material and easily identify any errors, there is still the process of analyzing what has been assimilated. To truly understand a technology, an individual must be able to recognize valid patterns, and to easily spot invalid patterns.</span></span></p>
<h3 style="margin:auto 0;"><a name="hpaoot"><span style="font-family:&#34;"><span style="font-size:medium;">How People Approach Object-Oriented Technology</span></span></a><span style="font-family:&#34;"><span style="font-size:medium;"> </span></span></h3>
<h1 style="margin:auto 0;"><a name="hpaoot"><span style="font-family:'Verdana','sans-serif';">How People Approach Object-Oriented Technology</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<p><span style="font-family:&#34;"><span style="font-size:small;">Object-oriented technology is both immense and far-reaching. End users of computer systems and computer-based systems notice the effects of object-oriented technology in the form of increasingly easy-to-use software applications and operating systems and in more flexible services being provided by such industries as banking, telecommunications, and cable television. For the software engineer, object-oriented technology encompasses object-oriented programming languages, object-oriented development methodologies, management of object-oriented projects, object-oriented computer hardware, and object-oriented computer aided software engineering, among others.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">It is not surprising, therefore, that there is some confusion regarding object-oriented terms and concepts. In this article, we will provide the reader with working definitions for object-oriented terms and concepts that are necessary for a reader to acquire a basic understanding of object-oriented technology.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Many of the terms commonly used in object-oriented technology were originally used to describe object-oriented programming (coding) concepts. Specifically, although the terms were borrowed from a non-computer-software perspective, they were first used extensively to describe concepts embodied in object-oriented programming languages, such as Smalltalk, C++, and Eiffel. However, these terms are quite useful even if one never intends to write any software at all.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">For example, an industrial modeler could create an object-oriented model of a plastics manufacturing facility. Molding machines, plastic parts, and even the "recipes" (proportional combinations) of the chemicals used to create the various plastics could all be described in object-oriented terms. Further, dynamic and static relationships among these items could also be described in object-oriented terms.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Finally, keep in mind that there is no one ultimate set of definitions for object-oriented terms and concepts. Depending on who you are talking to, terms and definitions will vary slightly. This is normal; in different parts of the United States, the same breakfast item might be referred to as a pancake, a griddle cake, a flapjack, or a hot cake. Even in technical arenas, this variation in terminology is common. A chemist might use the terms "valance" and "oxidation state" to identify the same concept.</span></span></p>
<h3 style="margin:auto 0;"><a name="ootc"><span style="font-family:&#34;"><span style="font-size:medium;">Object-Oriented Terms and Concepts</span></span></a></h3>
<h1 style="margin:auto 0;"><a name="ootc"><span style="font-family:'Verdana','sans-serif';">Object-Oriented Terms and Concepts</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<h3 style="margin:auto 0;"><span style="font-size:medium;"></span></h3>
<h4 style="margin:auto 0;"><a name="objects"><span style="font-family:&#34;"><span style="font-size:small;">Objects</span></span></a><span style="font-family:&#34;"><span style="font-size:small;"> </span></span></h4>
<p><span style="font-size:small;"><strong><span style="font-family:&#34;">Objects</span></strong><span style="font-family:&#34;"> are the physical and conceptual things we find in the universe around us. Hardware, software, documents, human beings, and even concepts are all examples of objects. For purposes of modeling his or her company, a chief executive officer could view employees, buildings, divisions, documents, and benefits packages as objects. An automotive engineer would see tires, doors, engines, top speed, and the current fuel level as objects. Atoms, molecules, volumes, and temperatures would all be objects a chemist might consider in creating an object-oriented simulation of a chemical reaction. Finally, a software engineer would consider stacks, queues, windows, and check boxes as objects.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Objects are thought of as having state. The <strong>state</strong> of an object is the condition of the object, or a set of circumstances describing the object. It is not uncommon to hear people talk about the "state information" associated with a particular object. For example, the state of a bank account object would include the current balance, the state of a clock object would be the current time, the state of an electric light bulb would be "on" or "off." For complex objects like a human being or an automobile, a complete description of the state might be very complex. Fortunately, when we use objects to model real world or imagined situations, we typically restrict the possible states of the objects to only those that are relevant to our models.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">We also think of the state of an object as something that is internal to an object. For example, if we place a message in a mailbox, the (internal) state of the mailbox object is changed, whereas the (internal) state of the message object remains unchanged.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Sometimes people think of objects as being strictly static. That is, the state of an object will not change unless something outside of the object requests the object to change its state. Indeed, many objects are passive (static). A list of names does not spontaneously add new names to itself, nor would we expect it to spontaneously delete names from itself.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">However, it is possible for some objects to change their own state. If an object is capable of spontaneously changing its own state, we refer to it as an "<strong>object with life</strong>." (Objects with life are sometimes also called "active objects" or "actors.") Clocks and timers are common examples of objects with life. If we were modeling a business process, we would recognize that salespeople and customers were also objects with life.</span></span></p>
<h4 style="margin:auto 0;"><a name="classes"><span style="font-family:&#34;"><span style="font-size:small;">Classes, Metaclasses, Parameterized Classes, and Exemplars</span></span></a><span style="font-family:&#34;"><span style="font-size:small;"> </span></span></h4>
<h1 style="margin:auto 0;"><a name="classes"><span style="font-family:'Verdana','sans-serif';">Classes, Metaclasses, Parameterized Classes, and Exemplars</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<p><span style="font-family:&#34;"><span style="font-size:small;">There are two broad categories of objects: classes and instances. Users of object-oriented technology usually think of classes as containing the information necessary to create instances, i.e., the structure and capabilities of an instance is determined by its corresponding class. There are three commonly used (and different) views on the definition for "class":</span></span></p>
<table class="MsoNormalTable" border="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#ece9d8;padding:0.75pt;">
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">A <strong>class</strong> is a pattern, template, or blueprint for a category of structurally identical items. The items created using the class are called <strong>instances</strong>. This is often referred to as the "class as a `cookie cutter'" view. As you might guess, the instances are the "cookies."</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">A <strong>class</strong> is a thing that consists of both a pattern and a mechanism for creating items based on that pattern. This is the "class as an `instance factory'" view; <strong>instances</strong> are the individual items that are "manufactured" (created) using the class's creation mechanism.</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">A <strong>class</strong> is the set of all items created using a specific pattern. Said another way, the class is the set of all <strong>instances</strong> of that pattern. </span></span></li>
</ul>
</td>
<td style="background-color:transparent;border:#ece9d8;padding:0.75pt;">
<p class="MsoNormal" style="margin:0;"> </p>
</td>
</tr>
</tbody>
</table>
<p><span style="font-family:&#34;"><span style="font-size:small;">In this article, we will use the definition of a "class an `instance factory.'"</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">We should note that it is possible for an instance of a class to also be a class. A <strong>metaclass</strong> is a class whose instances themselves are classes. This means when we use the instance creation mechanism in a metaclass, the instance created will itself be a class. The instance creation mechanism of this class can, in turn, be used to create instances -- although these instances may or may not themselves be classes.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">A concept very similar to the metaclass is the parameterized class. A <strong>parameterized class</strong> is a template for a class wherein specific items have been identified as being required to create non-parameterized classes based on the template. In effect, a parameterized class can be viewed as a "fill in the blanks" version of a class. One cannot directly use the instance creation mechanism of a parameterized class. First, we must supply the required parameters, resulting in the creation of a non-parameterized class. Once we have a non-parameterized class, we can use its creation mechanisms to create instances.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">In this article, we will use the term "class" to mean metaclass, parameterized class, or a class that is neither a metaclass nor a parameterized class. We will make a distinction only when it is necessary to do so. Further, we will occasionally refer to "non-class instances." A <strong>non-class instance</strong> is an instance of a class, but is itself not a class. An instance of a metaclass, for example, would <em>not</em> be a non-class instance.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">In this article, we will sometimes refer to "instantiation." <strong>Instantiation</strong> has two common meanings:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">as a <em>verb</em>, instantiation is the process of creating an instance of a class, and</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">as a <em>noun</em>, an instantiation is an instance of a class. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">Some people restrict the use of the term "object" to instances of classes. For these people, classes are not objects. However, when these people are confronted with the concepts of metaclasses and parameterized classes, they have a difficulty attempting to resolve the "problems" these concepts introduce. For example, is a class that is an instance of a metaclass an object -- even though it is itself a class? In this article, we will use the term "object" to refer to both classes and their instances. We will only distinguish between the two when needed.</span></span></p>
<h4 style="margin:auto 0;"><a name="bbi"><span style="font-family:&#34;"><span style="font-size:small;">Black Boxes and Interfaces</span></span></a><span style="font-family:&#34;"><span style="font-size:small;"> </span></span></h4>
<h1 style="margin:auto 0;"><a name="bbi"><span style="font-family:'Verdana','sans-serif';">Black Boxes and Interfaces</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<p><span style="font-family:&#34;"><span style="font-size:small;">Objects are "black boxes." Specifically, the underlying implementations of objects are hidden from those that use the object. In object-oriented systems, it is only the producer (creator, designer, or builder) of an object that knows the details about the internal construction of that object. The consumers (users) of an object are denied knowledge of the inner workings of the object, and must deal with an object via one of its three distinct interfaces:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">the "public" interface. This is the interface that is open (visible) to everybody.</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">the "inheritance" interface. This is the interface that is accessible only by direct specializations of the object. (We will discuss inheritance and specialization later in this chapter.) In class-based object-oriented systems, only classes can provide an inheritance interface.</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">the "parameter" interface. In the case of parameterized classes, the parameter interface defines the parameters that must be supplied to create an instance of the parameterized class. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">Another way of saying that an item is in the public interface of an object is to say that the object "exports" that item. Similarly, when an object requires information from outside of itself (e.g., as with the parameters in a parameterized class), we can say that the object needs to "import" that information.</span></span></p>
<h1 style="margin:auto 0;"><a name="aggregation"><span style="font-family:'Verdana','sans-serif';">Aggregation</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<p><span style="font-family:&#34;"><span style="font-size:small;">It is, of course, possible for objects to be composed of other objects. <strong>Aggregation</strong> is either:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">the process of creating a new object from two or more other objects, or</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">an object that is composed of two or more other objects. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">For example, a date object could be fashioned from a month object, a day object, and a year object. A list of names object, for example, can be thought of as containing many name objects.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">A <strong>monolithic object </strong>is an object that has no externally-discernible structure. Said another way, a monolithic object does not appear to have been constructed from two or more other objects. Specifically, a monolithic object can only be treated as a cohesive whole. Those outside of a monolithic object cannot directly interact with any (real or imagined) objects within the monolithic object. A radio button in a graphical user interface (GUI) is an example of a monolithic object.</span></span></p>
<p><span style="font-size:small;"><strong><span style="font-family:&#34;">Composite objects</span></strong><span style="font-family:&#34;"> are objects that have an externally-discernible structure, and the structure can be addressed via the public interface of the composite object. The objects that comprise a composite object are referred to as <strong>component objects</strong>. Composite objects meet one or both of the following criteria:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">the state of a composite object is directly affected by the presence or absence of one or more of its component objects, and/or</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">the component objects can be directly referenced via the public interface of their corresponding composite object. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">It is useful to divide composite objects into two subcategories: heterogeneous composite objects and homogeneous composite objects:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">A <strong>heterogeneous composite object</strong> is a composite object that is conceptually composed of component objects that are not all conceptually the same. For example, a date (made up of a month object, a day object, and a year object) is a heterogeneous composite object.</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">A <strong>homogeneous composite object</strong> is a composite object that is conceptually composed of component objects that are all conceptually the same. For example, a list of addresses is a homogeneous composite object. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">The rules for designing heterogeneous composite objects are different from the rules for designing homogeneous composite objects.</span></span></p>
<h4 style="margin:auto 0;"><a name="sai"><span style="font-family:&#34;"><span style="font-size:small;">Specialization and Inheritance</span></span></a><span style="font-family:&#34;"><span style="font-size:small;"> </span></span></h4>
<h1 style="margin:auto 0;"><a name="sai"><span style="font-family:'Verdana','sans-serif';">Specialization and Inheritance</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<p><span style="font-family:&#34;"><span style="font-size:small;"></p>
<h4 style="margin:auto 0;"><span style="font-family:'Verdana','sans-serif';"></span> </h4>
<p></span></span></p>
<p> </p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Aggregation is not the only way in which two objects can be related. One object can be a specialization of another object. <strong>Specialization </strong>is either:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">the process of defining a new object based on a (typically) more narrow definition of an existing object, or</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">an object that is directly related to, and more narrowly defined than, another object. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">Specialization is usually associated with classes. It is usually only in the so-called "classless" object-oriented systems that we think of specialization for objects other than classes.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Depending on their technical background, there are a number of different ways in which people express specialization. For example, those who are familiar with an object-oriented programming language called Smalltalk refer to specializations as "subclasses" and to the corresponding <strong>generalizations</strong> of these specializations as "superclasses." Those with a background in the C++ programming language use the term "derived class" for specialization and "base class" for corresponding generalizations.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">It is common to say that everything that is true for a generalization is also true for its corresponding specialization. We can, for example, define "checking accounts" and "savings accounts" as specializations of "bank accounts." Another way of saying this is that a checking account is a kind of bank account, and a savings account is a kind of bank account. Still another way of expressing this idea is to say that everything that was true for the bank account is also true for the savings account and the checking account.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">In an object-oriented context, we speak of specializations as "inheriting" characteristics from their corresponding generalizations. <strong>Inheritance</strong> can be defined as the process whereby one object acquires (gets, receives) characteristics from one or more other objects. Some object-oriented systems permit only <strong>single inheritance,</strong> a situation in which a specialization may only acquire characteristics from a single generalization. Many object-oriented systems, however, allow for <strong>multiple inheritance</strong>, a situation in which a specialization may acquire characteristics from two or more corresponding generalizations.</span></span></p>
<table class="MsoNormalTable" border="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#ece9d8;padding:0.75pt;">
<p class="MsoNormal" style="margin:0;"> </p>
</td>
<td style="background-color:transparent;border:#ece9d8;padding:0.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-family:&#34;"><span style="font-size:small;">Our previous discussion of the bank account, checking account, and savings account was an example of single inheritance. A telescope and a television set are both specializations of "device that enables one to see things far away." A television set is also a kind of "electronic device." You might say that a television set acquires characteristics from two different generalizations, "device that enables one to see things far away" and "electronic device." Therefore, a television set is a product of multiple inheritance.</span></span></p>
</td>
</tr>
</tbody>
</table>
<h4 style="margin:auto 0;">
<h1 style="margin:auto 0;"><a name="ac"><span style="font-family:'Verdana','sans-serif';"><span style="font-size:small;">Abstract Classes</span></span></a><span style="font-family:'Verdana','sans-serif';"><span style="font-size:small;"> </span></span></h1>
<p><a name="ac"><span style="font-family:&#34;"><span style="font-size:small;">Abstract Classes</span></span></a><span style="font-family:&#34;"><span style="font-size:small;"> </span></span></h4>
<p><span style="font-family:&#34;"><span style="font-size:small;">We usually think of classes as being complete definitions. However, there are situations where incomplete definitions are useful, and classes that represent these incomplete definitions are equally useful. For example, in everyday conversation, we might talk about such items as bank accounts, insurance policies, and houses. In object-oriented thinking, we often isolate useful, but incomplete, concepts such as these into their own special classes.</span></span></p>
<p><span style="font-size:small;"><strong><span style="font-family:&#34;">Abstract classes</span></strong><span style="font-family:&#34;"> are classes that embody coherent and cohesive, but incomplete, concepts, and in turn, make these characteristics available to their specializations via inheritance. People sometimes use the terms "partial type" and "abstract superclass" as synonyms for abstract class. While we would never create instances of abstract classes, we most certainly would make their individual characteristics available to more specialized classes via inheritance.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">For example, consider the concept of an automobile. On one hand, most people know what an automobile is. On the other hand, "automobile" is not a complete definition for any vehicle. It would be quite accurate to describe "automobile" as the set of characteristics that make a thing an automobile, in other words, the "essence of automobile-ness."</span></span></p>
<h4 style="margin:auto 0;"><a name="operations"><span style="font-family:&#34;"><span style="font-size:small;">Operations</span></span></a><span style="font-family:&#34;"><span style="font-size:small;"> </span></span></h4>
<h1 style="margin:auto 0;"><a name="operations"><span style="font-family:'Verdana','sans-serif';">Operations</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<p><span style="font-family:&#34;"><span style="font-size:small;">The public interface of an object typically contains three different categories of items:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">operations (sometimes referred to as "method selectors," "method interfaces," "messages," or "methods"),</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">constants, and</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">exceptions. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">An operation in the public interface of an object advertises a functional capability of that object. For example, "deposit" would be an operation in the public interface of a bank account object, "what is current temperature" would be an operation in the public interface of a temperature sensor object, and "increment" would be an operation in the public interface of a counter object.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">The actual algorithm for accomplishing an operation is referred to as a <strong>method</strong>. Unlike operations, methods are not in the public interface for an object. Rather, methods are hidden on the inside of an object. So, while users of bank account objects would know that they could make a deposit into a bank account, they would be unaware of the details as to how that deposit actually got credited to the bank account.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">We refer to the operations in the public interface of an object as "suffered operations." <strong>Suffered operations</strong> are operations that meet two criteria: they are things that happen to an object, and they are in the public interface of that object. For example, we can say that a bank account "suffers" the operation of having a deposit made into it. The bank account can also "suffer" the operation of being queried as to its current balance. Some people also refer to suffered operations as "exported operations."</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">There are three broad categories of <em>suffered</em> operations, i.e.:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">A <strong>selector</strong> is an operation that tells us something about the state of an object, but cannot, by definition, change the state of the object. An operation that tells us the current balance of a bank account is an example of a selector operation.</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">A <strong>constructor</strong> is an operation that has the ability to change the state of an object. For example, an operation in the public interface to a mailbox object that added a message to the mailbox would be a constructor operation. (Please note that some people restrict the definition of the term "constructor" to those operations that cause instances of a class to come into existence.)</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">In the context of a homogeneous composite object, an <strong>iterator</strong> is an operation that allows its users to visit (access) each of the component objects that make up the homogeneous composite object. If we have a list of addresses, for example, and we wish to print the entire list, an iterator would allow us to visit each address object within the list and then, in turn, to print each address. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">Iterators can be further divided into two broad categories: active (open) iterators and passive (closed) iterators. Active iterators are objects in their own right. Passive iterators are implemented as operations in the interface of the object over which they allow iteration. Passive iterators are further broken down into selective iterators and constructive iterators. Passive selective iterators do not allow their users to change the object over which the iteration takes place. Passive constructive iterators do allow users to change the object over which iteration takes place.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">We can also describe suffered operations as primitive or composite. A <strong>primitive operation</strong> is an operation that cannot be accomplished simply, efficiently, and reliably without direct knowledge of the underlying (hidden) implementation of the object. As an example, we could argue that an operation that added an item to a list object, or an operation that deleted an item from a list object were primitive operations with respect to the list object.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Suppose that we wanted to create a "swap operation," an operation that would swap in a new item in a list, while at the same time swapping out an old item in the same list. This is not a primitive operation since we can accomplish this with a simple combination of the delete operation (deleting the old item) followed by the add operation (adding the new item). The swap operation is an example of a composite operation. A <strong>composite operation</strong> is any operation that is composed, or can be composed, of two or more primitive operations.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Sometimes objects need help in maintaining their characteristics. Suppose, for example, that we wanted to create a "generic ordered list" object. An ordered list is a list that must order its contents from the smallest to the largest. Specifically, every time we add an item to our ordered list, that item would have to be placed in its proper position with respect to all the other items already in the list. By "generic," we mean a template that can be instantiated with the category (class) of items we wish to place in the ordered list.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">It would not be unreasonable to implement this object as a parameterized class. Obviously, one of the parameters would be the category of items (e.g., class) that we desired to place in the list. For example, could instantiate (make an instance) the generic ordered list with a "name class" resulting in the creation of an "ordered list of names class."</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">There is a problem, however. Given that we could instantiate the generic ordered list with just about any category of items, how can we be sure that the ordered lists will know how to properly maintain order <em>-- no matter what we use to instantiate the generic ordered list?</em> Suppose, for example, that we wanted an ordered list of "fazoomas." How could the generic list class tell if one fazooma was greater than or less than another fazooma?</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">A solution would be for the generic ordered list to require a second parameter, a parameter over and above the category of items (class) that we desired to place in the list. This second parameter would be a "&#60;" (less than) operation that worked with the category of items to be placed in the list. In the case of our ordered list of fazoomas, this second parameter would be a "&#60;" that works with fazoomas.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">The "&#60;" that worked with fazoomas is an example of a required operation. A <strong>required operation</strong> is an operation that an object needs to maintain its outwardly observable characteristics, but which the object cannot supply itself. Some people refer to required operations as "imported operations."</span></span></p>
<h4 style="margin:auto 0;"><a name="constants"><span style="font-family:&#34;"><span style="font-size:small;">Constants</span></span></a></h4>
<h1 style="margin:auto 0;"><a name="constants"><span style="font-family:'Verdana','sans-serif';">Constants</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<h4 style="margin:auto 0;"><span style="font-size:small;"></span></h4>
<p><span style="font-family:&#34;"><span style="font-size:small;">In addition to suffered operations, the public interface of an object can also contain constants. <strong>Constants</strong> are objects of constant state. Imagine that we want to create a "bounded list of addresses class." A bounded list is a list that has a fixed maximum number of elements. A bounded list can be empty, and it can contain fewer than the maximum number of elements. It can even contain the maximum number of elements, but it can never contain more than the defined maximum number of elements.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Assume that we place a constant in the public interface of our bounded list of addresses. This constant represents the maximum number of elements that can be placed in the bounded list. Assume also that there is a suffered operation that will tell us how many elements (addresses, in our example) are currently in the bounded list. We can now determine how much room is available in the bounded list by inquiring how many addresses are already in the list, and then subtracting this from the previously-defined constant.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">In some cases, as with the bounded list example above, constants are provided more for convenience than necessity. In other cases, such as in the case of encryption algorithms needing a "seed value," constants are an absolute requirement.</span></span></p>
<h4 style="margin:auto 0;"><a name="exceptions"><span style="font-family:&#34;"><span style="font-size:small;">Exceptions</span></span></a><span style="font-family:&#34;"><span style="font-size:small;"> </span></span></h4>
<h1 style="margin:auto 0;"><a name="exceptions"><span style="font-family:'Verdana','sans-serif';">Exceptions</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<p><span style="font-family:&#34;"><span style="font-size:small;">A third category of items that can be found in the public interface of objects is exceptions. <strong>Exceptions</strong> have two different definitions:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">an event that causes suspension of normal application execution, and</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">a set of information directly relating to the event that caused suspension of normal application execution. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">Exceptions can be contrasted with an older, less reliable technology: "error codes." The idea behind error codes was fairly simple. You would request that an application, or part of an application, accomplish some work. One of the pieces of information that would be returned to the requester would be an error code. If all had gone well, the error code would typically have a value of zero. If any problems had occurred, the error code would have a non-zero value. It was also quite common to associate different non-zero values of an error code with specific errors.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Error codes suffered from two major problems:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">No one was forced to actually check the value of returned error codes.</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Changes (additions, deletions, and modifications) in the meanings of the special values assigned to error codes were not automatically passed on to interested parties. Tracking the effects of a changed error code value often consumed a significant amount of resources. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">To understand how exceptions directly address both of these issues, we first need to understand how exceptions typically work:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Exceptions may be defined by the environment or by the user.</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">When an exceptional (but not unforeseen) condition occurs, an appropriate exception is activated. (People use different terms to express the activation of an exception. The most common is "raise." Less commonly, people use the terms "throw" or "activate.") This activation may be automatic (controlled by the environment) or may be expressly requested by the designer of the object or application. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">Examples of exceptional conditions include trying to remove something from an empty container, directing an elevator on the top floor to "go up," and attempting to cause a date to take on an invalid value like "February 31, 1993."</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">Once the exception is activated, normal application execution stops and control is transferred to a locally defined exception handler, if one is present. If no locally defined exception handler is present or if the exception handler is not equipped to handle the exception, the exception is propagated to the next higher level of the application. <em>Exceptions cannot be ignored.</em> An exception will continue to be sent to higher levels of the application until it is either turned off or the application ceases to function.</span></span></li>
<li class="MsoNormal"><span style="font-family:&#34;"><span style="font-size:small;">An exception handler checks to see what type of exception has been activated. If the exception is one that the handler recognizes, a specific set of actions is taken. Executing a set of actions in response to an exception is known as "handling the exception." Handling an exception deactivates the exception; the exception will not be propagated any further. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">Unlike error codes, exceptions cannot be ignored. Once an exception has been activated, it demands attention. In object-oriented systems, exceptions are placed in the public interfaces of objects. Changes in the public interfaces of objects very often require an automatic rechecking of all other objects that invoke operations in the changed objects. Thus, changes in exceptions result in at least a partially automated propagation of change information.</span></span></p>
<h4 style="margin:auto 0;"><a name="ococ"><span style="font-family:&#34;"><span style="font-size:small;">Object Coupling and Object Cohesion</span></span></a><span style="font-family:&#34;"><span style="font-size:small;"> </span></span></h4>
<h1 style="margin:auto 0;"><a name="ococ"><span style="font-family:'Verdana','sans-serif';">Object Coupling and Object Cohesion</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<p><span style="font-family:&#34;"><span style="font-size:small;">Engineers have known for centuries that the less any one part of a system knows about any other part of that same system, the better the overall system. Systems whose components are highly independent of each other are easier to fix and enhance than systems where there are strong interdependencies among some or all of the components. Highly independent system components are possible when there is minimal coupling among the components, and each component is highly cohesive.</span></span></p>
<table class="MsoNormalTable" border="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#ece9d8;padding:0.75pt;">
<p class="MsoNormal" style="margin:0;"> </p>
</td>
<td style="background-color:transparent;border:#ece9d8;padding:0.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-family:&#34;"><span style="font-size:small;">Coupling is a measure of the strength of the connection between any two system components. The more any one component knows about another component, the tighter (worse) the coupling is between those two components. Cohesion is a measure of how logically related the parts of an individual component are to each other, and to the overall component. The more logically related the parts of a component are to each other the higher (better) the cohesion of that component.</span></span></p>
</td>
</tr>
</tbody>
</table>
<p><span style="font-family:&#34;"><span style="font-size:small;">The objects that make up an object-oriented system exhibit object coupling and object cohesion. <strong>Object coupling</strong> describes the degree of interrelationships among the objects that make up a system. The more any one object knows about any other object in the system, the tighter (worse) the coupling is between those two objects.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">To construct systems from objects, we must couple (to some degree) the objects that comprise the system. This is <em>necessary </em>object coupling. However, if in the design of an individual object, we give that object direct knowledge of other specific objects, we are unnecessarily coupling the objects. <em>Unnecessary </em>object coupling reduces both the reusability of individual objects, and the reliability of the systems that contain unnecessarily coupled objects.</span></span></p>
<table class="MsoNormalTable" border="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#ece9d8;padding:0.75pt;">
<p class="MsoNormal" style="margin:0;"> </p>
</td>
<td style="background-color:transparent;border:#ece9d8;padding:0.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><strong><span style="font-family:&#34;">Object cohesion</span></strong><span style="font-family:&#34;">, on the other hand, is a measure of how logically related the components of the <em>external</em> view of an object are to each other. For example, if we are told that a date object is comprised of a month object, a day object, a year object, and the color blue, we should recognize that the color blue is not appropriate, and lowers the cohesion of the date object. We want our objects to be as cohesive as possible for two reasons. First, objects with low cohesion are more likely to be changed, and are more likely to have undesirable side effects when they are changed. Second, objects with low cohesion are seldom easily reusable.</span></span></p>
</td>
</tr>
</tbody>
</table>
<h4 style="margin:auto 0;"><a name="systems"><span style="font-family:&#34;"><span style="font-size:small;">Systems of Objects</span></span></a><span style="font-family:&#34;"><span style="font-size:small;"> </span></span></h4>
<h1 style="margin:auto 0;"><a name="systems"><span style="font-family:'Verdana','sans-serif';">Systems of Objects</span></a><span style="font-family:'Verdana','sans-serif';"> </span></h1>
<p><span style="font-family:&#34;"><span style="font-size:small;">In constructing object-oriented models and object-oriented applications, one quickly finds that single classes and single instances are not enough. You need some way of creating and dealing with large objects. A <strong>system of objects</strong> is defined as two or more interacting or interrelated, non-nested objects. (We exclude simple aggregations of composite objects from our definition of systems of objects.)</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Systems of objects fall into two general categories:</span></span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;"><strong><span style="font-family:&#34;">kits</span></strong><span style="font-family:&#34;">, which are collections of items (classes, metaclasses, parameterized classes, non-class instances, other kits, and/or systems of interacting objects) all of which support a single, large, coherent, object-oriented concept, such as computer graphics windows or insurance policies. There may indeed be some physical connection among some of the members of a given kit. However, kits are "granular." While all the components of a kit are logically related, there are very few physical connections that bind them together.</span></span></li>
<li class="MsoNormal"><span style="font-size:small;"><strong><span style="font-family:&#34;">systems of interacting objects</span></strong><span style="font-family:&#34;">, which are collections of items (classes, metaclasses, parameterized classes, non-class instances, kits, and/or other systems of interacting objects) all of which support a single, large, coherent, object-oriented concept, and in which there must be a direct or indirect physical connection between any two arbitrary objects within the collection. Further, systems of interacting objects have at least one internal, independently executing thread of control. Lastly, systems of interacting objects may exhibit multiple, completely disjoint public interfaces. </span></span></li>
</ul>
<p><span style="font-family:&#34;"><span style="font-size:small;">Kits resemble libraries. Say, for example, that we had to create a computer application with a graphical user interface. Graphical user interfaces normally contain several different types of windows. It would be very useful if we had a library of windows and window components from which we could construct any window we desired. Windows are objects, and the components of windows (buttons and check boxes) are themselves objects. A collection of windows and window components can be viewed as a kit.</span></span></p>
<p><span style="font-family:&#34;"><span style="font-size:small;">Systems of interacting objects, on the other hand, resemble applications. For example, suppose that we wanted to construct an object-oriented application that controlled the elevators in a particular building. We would assemble elevators, buttons, lamps, panels, and other objects into a working application that would control the elevators. Such an application would not be viewed as a library, but as a highly cohesive whole. The elevator controller application is a system of interacting objects.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:&#34;"><span style="font-size:small;"> </span></span></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Serialization for Generic Types in C# .NET]]></title>
<link>http://shiman.wordpress.com/?p=107</link>
<pubDate>Thu, 24 Jul 2008 06:40:52 +0000</pubDate>
<dc:creator>shiman</dc:creator>
<guid>http://shiman.wordpress.com/?p=107</guid>
<description><![CDATA[Serialization persists the state of an object to a stream. Serializing the instance of a generic typ]]></description>
<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Serialization persists the state of an object to a stream. Serializing the instance of a generic type is similar to a regular type. </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Serialization is done mostly with the <em>SerializationInfo</em> object. For generic types, there are additional overloads of the <em>SerializationInfo.AddValue</em> and <em>SerializationInfo.GetValue</em> methods for object types. This requires casting to and from object types.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">For serialization, the generic type must be adorned with the <em>Serializable</em> attribute.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The <em>GetObjectData</em> method implements the serialization of an object. This includes serializing both the metadata and instance data of the type. <em>GetObjectData</em> has a <em>SerializationInfo</em> and <em>StreamingContext</em> parameter. The <em>SerializationInfo.AddValue</em> method is called to serialize generic type content:</span></p>
<table class="MsoTableGrid" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:6.65in;background-color:transparent;border:black 1pt solid;padding:0 5.4pt;" width="638" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:Consolas;">public</span><span style="font-size:10pt;font-family:Consolas;"> <span style="color:#0000ff;">void</span> GetObjectData(<span style="color:#2b91af;">SerializationInfo</span> info, <span style="color:#2b91af;">StreamingContext</span> ctx)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>info.AddValue(<span style="color:#a31515;">"fielda"</span>, fielda, <span style="color:#0000ff;">typeof</span>(T));</span></p>
<p class="para" style="margin:auto 0;"><span style="font-size:10pt;font-family:Consolas;">}</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">To deserialize, add a two-argument constructor to the generic type. The arguments are a <em>SerializationInfo</em> and <em>StreamingContext</em> parameter. Call the <em>SerializationInfo.GetValue</em> method to rehydrate the instance:</span></p>
<table class="MsoTableGrid" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:6.65in;background-color:transparent;border:black 1pt solid;padding:0 5.4pt;" width="638" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:Consolas;">private</span><span style="font-size:10pt;font-family:Consolas;"> ZClass(<span style="color:#2b91af;">SerializationInfo</span> info, <span style="color:#2b91af;">StreamingContext</span> ctx)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>fielda = (T)info.GetValue(<span style="color:#a31515;">"fielda"</span>, <span style="color:#0000ff;">typeof</span>(T));</span></p>
<p class="para" style="margin:auto 0;"><span style="font-size:10pt;font-family:Consolas;">}</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Objects can be serialized in different formats, which is accomplished with formatters, such as the <em>BinaryFormatter</em> type. The <em>SoapFormatter</em> type cannot be used with generic types. Serialization also requires creating an appropriate stream, such as a <em>FileStream</em>. The stream is where the instance is serialized or deserialized. Call <em>BinaryFormatter.Serialize</em> to serialize a generic type instance. Conversely, call <em>BinaryFormatter.Deserialize</em> to deserialize.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The following program accepts a command-line argument. The <em>set</em> command instructs the program to serialize an instance of the <em>ZClass</em> generic type to a file. A <em>get</em> command asks the program to deserialize the <em>ZClass</em> generic type.</span></p>
<table class="MsoTableGrid" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:6.65in;background-color:transparent;border:black 1pt solid;padding:0 5.4pt;" width="638" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:Consolas;">using</span><span style="font-size:10pt;font-family:Consolas;"> System;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:Consolas;">using</span><span style="font-size:10pt;font-family:Consolas;"> System.Runtime.Serialization;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:Consolas;">using</span><span style="font-size:10pt;font-family:Consolas;"> System.Runtime.Serialization.Formatters.Binary;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:Consolas;">using</span><span style="font-size:10pt;font-family:Consolas;"> System.IO;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:Consolas;">namespace</span><span style="font-size:10pt;font-family:Consolas;"> Examples.Generics</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Program</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> Main(<span style="color:#0000ff;">string</span>[] args)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span><span style="color:#2b91af;">BinaryFormatter</span> binary = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">BinaryFormatter</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span><span style="color:#2b91af;">FileStream</span> file = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">FileStream</span>(<span style="color:#a31515;">"data.bin"</span>, <span style="color:#2b91af;">FileMode</span>.OpenOrCreate);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span><span style="color:#0000ff;">if</span> (args[0].ToLower() == <span style="color:#a31515;">"set"</span>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>       </span><span>         </span><span style="color:#2b91af;">ZClass</span>&#60;<span style="color:#0000ff;">int</span>&#62; obj = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ZClass</span>&#60;<span style="color:#0000ff;">int</span>&#62;(5);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>                </span>binary.Serialize(file, obj);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>                </span><span style="color:#0000ff;">return</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span><span style="color:#0000ff;">if</span> (args[0].ToLower() == <span style="color:#a31515;">"get"</span>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>                </span><span style="color:#2b91af;">ZClass</span>&#60;<span style="color:#0000ff;">int</span>&#62; obj = (<span style="color:#2b91af;">ZClass</span>&#60;<span style="color:#0000ff;">int</span>&#62;)binary.Deserialize(file);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>                </span><span style="color:#2b91af;">Console</span>.WriteLine(obj.GetValue());</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>                </span><span style="color:#0000ff;">return</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>[<span style="color:#2b91af;">Serializable</span>]</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">ZClass</span>&#60;T&#62;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:#0000ff;">public</span> ZClass(T init)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span>fielda = init;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> GetObjectData(<span style="color:#2b91af;">SerializationInfo</span> info, <span style="color:#2b91af;">StreamingContext</span> ctx)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span>info.AddValue(<span style="color:#a31515;">"fielda"</span>, fielda, <span style="color:#0000ff;">typeof</span>(T));</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:#0000ff;">private</span> ZClass(<span style="color:#2b91af;">SerializationInfo</span> info, <span style="color:#2b91af;">StreamingContext</span> ctx)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>         </span><span>   </span>fielda = (T)info.GetValue(<span style="color:#a31515;">"fielda"</span>, <span style="color:#0000ff;">typeof</span>(T));</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> SetValue(T data)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span>fielda = data;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:#0000ff;">public</span> T GetValue()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span><span style="color:#0000ff;">return</span> fielda;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:#0000ff;">private</span> T fielda = <span style="color:#0000ff;">default</span>(T);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;">}</span></p>
</td>
</tr>
</tbody>
</table>
<p class="para" style="margin:auto 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Senior Software Engineer]]></title>
<link>http://spillerlaszlo.wordpress.com/?p=258</link>
<pubDate>Wed, 23 Jul 2008 14:59:33 +0000</pubDate>
<dc:creator>Spiller László</dc:creator>
<guid>http://spillerlaszlo.wordpress.com/?p=258</guid>
<description><![CDATA[Position Summary

As a key figure in an international engineering team, you will be responsible for]]></description>
<content:encoded><![CDATA[<p>Position Summary</p>
<ul>
<li>As a key figure in an international engineering team, you will be responsible for requirements gathering, systems analysis, design and build/implementation of 3 tier Java technology solutions which support worldwide premium products. The services for which this engineer is involved with support revenue generation from external customers in multiple countries and time zones. The chosen candidate will work for the Manager of Software Engineering for International and work closely with several teams who are based locally or in an offshore location. As well as hands on development, there is a significant proportion of the role required to provide internal consultation to business customers on technical solutions and provide input for scoping project costs. You will also be responsible for liaising with technical and non-technical staff from in the US, Japan and Europe, along with as necessary external developers from third party partners. This role involves a mix of hands on development and business facing consultation.</li>
</ul>
<p>Job Responsibilities<br />
• Liaise with technical and non technical customers worldwide to produce and deliver business and technical requirements specifications.<br />
• Undertake system / architectural design and review employing best industry practice.<br />
• Take responsibility for producing detailed system designs and implementation plans, working with the rest of the engineering team and ensure all team members produce consistent output in line with best practice.<br />
• Develop and ensure solutions are tested in accordance with the QA team<br />
• Ensure there is consistent production of design, maintenance and operational documentation.<br />
• Maintain and enhance the development environment and advance the technical systems architectures and technologies.<br />
• Support global development teams and external clients in the use of the standard technology platform.</p>
<p> Qualifications For Position<br />
• Software development of computer sciences degree.</p>
<p>Experience For Position<br />
• 5+ years working in a recognized professional software / internet development company.<br />
• 5+ years development and delivery of online products or services.<br />
• 5+ years architectural design and implementation of J2SE/EE solutions.<br />
• 3 years exposure to end-user facing web development frameworks.<br />
• 3 years exposure and practice in all areas of the software development life cycle. (requirements, design, implementation, testing, maintenance)<br />
• Experience working with non-technical customers and having the unique ability to convey technical issues in a business context.</p>
<p>Technology Experience<br />
• Operating systems: Windows 2000/XP, UNIX/Linux, Dos<br />
• Programming: JSP, MVC Frameworks, Spring, JMS, JDBC, Servlets, EJB, XML, HTML, SQL<br />
• Design Methodologies and tools: UML, OOA/D, Rational<br />
• Application Environment: Weblogic  6+ , Tomcat, JBoss, MS SQL Server 2000+<br />
• Java Development Environment: Eclipse<br />
• Source code control systems. (e.g. Microsoft VSS, CVS, SVN, Perforce)</p>
<p>Specific Skills Required<br />
• Highly competency in J2EE architecture and development.<br />
• High competency in relational database development<br />
• Excellent communication and interpersonal skills.<br />
• Excellent written and spoken English</p>
<p>Advantageous Experience<br />
• Experience of commerce related projects.<br />
• Experience of leading teams of developers.<br />
• International experience.</p>
<p><a href="mailto:laszlo_spiller@kellyservices.hu">laszlo_spiller@kellyservices.hu</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Web Applications Java Developer]]></title>
<link>http://spillerlaszlo.wordpress.com/?p=252</link>
<pubDate>Wed, 23 Jul 2008 11:13:57 +0000</pubDate>
<dc:creator>Spiller László</dc:creator>
<guid>http://spillerlaszlo.wordpress.com/?p=252</guid>
<description><![CDATA[The ideal candidate will possess the following skills:
Technical:

Strong hands-on Java development ]]></description>
<content:encoded><![CDATA[<p>The ideal candidate will possess the following skills:</p>
<p><strong>Technical:</strong></p>
<ul>
<li>Strong hands-on Java development experience, 5+ years</li>
<li>Strong presentation tier skills, including HTML, CSS, Javascript, with Ajax and similar technologies a definite plus.</li>
<li>UI Design and Usability testing skills</li>
<li>Knowledge of Spring framework (web MVC, AOP and data access), Hibernate and JDBC</li>
<li> Some experience with relational databases, preferably Sybase as plus</li>
<li>Recent JSP / JSTL and Servlet experience ideally on Apache / Tomcat</li>
<li>OO Development and Design Skills including UML and use of design patterns</li>
<li>Experience of Spring Webflow  framework development a bonus</li>
<li>Experience of developing on Linux / Unix platform</li>
<li>Demonstrable experience of working in all phases of the development life cycle</li>
<li>BS or MS in Computer Science or Engineering degree from a highly accredited academic institution</li>
</ul>
<p><strong>Non-technical: </strong></p>
<ul>
<li>Good inter-personal skills with ability to communicate effectively both orally and in writing</li>
<li>Must have the capacity to work effectively either in a team  or on his / her own</li>
<li>Strong analytical and organisational skills.</li>
<li>Must be able to adapt well to change.</li>
<li>Must be able to demonstrate intellectual capacity to learn very quickly and adapt to complex situations in a fast paced and demanding environment.</li>
</ul>
<p><a href="laszlo_spiller@kellyservices.hu">laszlo_spiller@kellyservices.hu</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Design Pattern - Part 1]]></title>
<link>http://afruj.wordpress.com/?p=245</link>
<pubDate>Tue, 22 Jul 2008 17:58:09 +0000</pubDate>
<dc:creator>afruj</dc:creator>
<guid>http://afruj.wordpress.com/?p=245</guid>
<description><![CDATA[In software engineering, a design pattern is a general reusable solution to a commonly occurring pro]]></description>
<content:encoded><![CDATA[<p>In <a title="Software engineering" href="http://en.wikipedia.org/wiki/Software_engineering">software engineering</a>, a <strong class="selflink">design pattern</strong> is a general reusable solution to a commonly occurring problem in <a title="Software design" href="http://en.wikipedia.org/wiki/Software_design">software design</a>. A design pattern is not a finished design that can be transformed directly into <a class="mw-redirect" title="Code (computer programming)" href="http://en.wikipedia.org/wiki/Code_%28computer_programming%29">code</a>. It is a description or template for how to solve a problem that can be used in many different situations. <a class="mw-redirect" title="Object-oriented" href="http://en.wikipedia.org/wiki/Object-oriented">Object-oriented</a> design patterns typically show relationships and <a title="Interaction" href="http://en.wikipedia.org/wiki/Interaction">interactions</a> between <a title="Class (computer science)" href="http://en.wikipedia.org/wiki/Class_%28computer_science%29">classes</a> or <a title="Object (computer science)" href="http://en.wikipedia.org/wiki/Object_%28computer_science%29">objects</a>, without specifying the final application classes or objects that are involved.</p>
<p>Patterns originated as an <a title="Pattern (architecture)" href="http://en.wikipedia.org/wiki/Pattern_%28architecture%29"> architectural concept</a> by <a title="Christopher Alexander" href="http://en.wikipedia.org/wiki/Christopher_Alexander">Christopher Alexander</a> (1977/79). In 1987, <a title="Kent Beck" href="http://en.wikipedia.org/wiki/Kent_Beck">Kent Beck</a> and <a title="Ward Cunningham" href="http://en.wikipedia.org/wiki/Ward_Cunningham">Ward Cunningham</a> began experimenting with the idea of applying patterns to <a class="mw-redirect" title="Programming" href="http://en.wikipedia.org/wiki/Programming">programming</a> and presented their results at the <a title="OOPSLA" href="http://en.wikipedia.org/wiki/OOPSLA">OOPSLA</a> conference that year. Design patterns gained popularity in <a title="Computer science" href="http://en.wikipedia.org/wiki/Computer_science">computer science</a> after the book <a title="Design Patterns" href="http://en.wikipedia.org/wiki/Design_Patterns"><em>Design Patterns: Elements of Reusable Object-Oriented Software</em></a> was published in <a title="1994" href="http://en.wikipedia.org/wiki/1994">1994</a>.</p>
<p>Classification:</p>
<p><a title="Design Patterns" href="http://en.wikipedia.org/wiki/Design_Patterns">Design Patterns</a> originally grouped design patterns into the categories <a title="Creational pattern" href="http://en.wikipedia.org/wiki/Creational_pattern">Creational Patterns</a>, <a title="Structural pattern" href="http://en.wikipedia.org/wiki/Structural_pattern">Structural Patterns</a>, and <a title="Behavioral pattern" href="http://en.wikipedia.org/wiki/Behavioral_pattern">Behavioral Patterns</a>, and described them using the concepts of <a class="mw-redirect" title="Delegation (computer science)" href="http://en.wikipedia.org/wiki/Delegation_%28computer_science%29">delegation</a>, <a class="mw-redirect" title="Aggregation (object-oriented programming)" href="http://en.wikipedia.org/wiki/Aggregation_%28object-oriented_programming%29">aggregation</a>, and <a title="Consultation (object-oriented programming)" href="http://en.wikipedia.org/wiki/Consultation_%28object-oriented_programming%29">consultation</a>.</p>
<h2><span class="mw-headline">Creational patterns</span></h2>
<p>These patterns have to do with class instantiation. They can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation to get the job done.</p>
<ul>
<li><a title="Abstract factory pattern" href="http://en.wikipedia.org/wiki/Abstract_factory_pattern">Abstract Factory</a> groups object factories that have a common theme.</li>
<li><a title="Builder pattern" href="http://en.wikipedia.org/wiki/Builder_pattern">Builder</a> constructs complex objects by separating construction and representation.</li>
<li><a title="Factory method pattern" href="http://en.wikipedia.org/wiki/Factory_method_pattern">Factory Method</a> creates objects without specifying the exact class to create.</li>
<li><a title="Prototype pattern" href="http://en.wikipedia.org/wiki/Prototype_pattern">Prototype</a> creates objects by cloning an existing object.</li>
<li><a title="Singleton pattern" href="http://en.wikipedia.org/wiki/Singleton_pattern">Singleton</a> restricts object creation for a class to only one instance.</li>
</ul>
<h2><span class="mw-headline">Structural patterns</span></h2>
<p>These concern class and object composition. They use inheritance to compose interfaces and define ways to compose objects to obtain new functionality.</p>
<ul>
<li><a title="Adapter pattern" href="http://en.wikipedia.org/wiki/Adapter_pattern">Adapter</a> allows classes with incompatible interfaces to work together by wrapping its own interface around that of an already existing class.</li>
<li><a title="Bridge pattern" href="http://en.wikipedia.org/wiki/Bridge_pattern">Bridge</a> decouples an abstraction from its implementation so that the two can vary independently.</li>
<li><a title="Composite pattern" href="http://en.wikipedia.org/wiki/Composite_pattern">Composite</a> composes one-or-more similar objects so that they can be manipulated as one object.</li>
<li><a title="Decorator pattern" href="http://en.wikipedia.org/wiki/Decorator_pattern">Decorator</a> dynamically adds/overrides behaviour in an existing method of an object.</li>
<li><a title="Facade pattern" href="http://en.wikipedia.org/wiki/Facade_pattern">Facade</a> provides a simplified interface to a large body of code.</li>
<li><a title="Flyweight pattern" href="http://en.wikipedia.org/wiki/Flyweight_pattern">Flyweight</a> reduces the cost of creating and manipulating a large number of similar objects.</li>
<li><a title="Proxy pattern" href="http://en.wikipedia.org/wiki/Proxy_pattern">Proxy</a> provides a placeholder for another object to control access, reduce cost, and reduce complexity.</li>
</ul>
<h2><span class="mw-headline">Behavioral patterns</span></h2>
<p>These design patterns are about classes objects communication. They are specifically concerned with communication between <strong>objects</strong>.</p>
<ul>
<li><a title="Chain-of-responsibility pattern" href="http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern">Chain of responsibility</a> delegates commands to a chain of processing objects.</li>
<li><a title="Command pattern" href="http://en.wikipedia.org/wiki/Command_pattern">Command</a> creates objects which encapsulate actions and parameters.</li>
<li><a title="Interpreter pattern" href="http://en.wikipedia.org/wiki/Interpreter_pattern">Interpreter</a> implements a specialized language.</li>
<li><a title="Iterator pattern" href="http://en.wikipedia.org/wiki/Iterator_pattern">Iterator</a> accesses the elements of an object sequentially without exposing its underlying representation.</li>
<li><a title="Mediator pattern" href="http://en.wikipedia.org/wiki/Mediator_pattern">Mediator</a> allows loose coupling between classes by being the only class that has detailed knowledge of their methods.</li>
<li><a title="Memento pattern" href="http://en.wikipedia.org/wiki/Memento_pattern">Memento</a> provides the ability to restore an object to its previous state (undo).</li>
<li><a title="Observer pattern" href="http://en.wikipedia.org/wiki/Observer_pattern">Observer</a> is a publish/subscribe pattern which allows a number of observer objects to see an event.</li>
<li><a title="State pattern" href="http://en.wikipedia.org/wiki/State_pattern">State</a> allows an object to alter its behavior when its internal state changes.</li>
<li><a title="Strategy pattern" href="http://en.wikipedia.org/wiki/Strategy_pattern">Strategy</a> allows one of a family of algorithms to be selected on-the-fly at runtime.</li>
<li><a title="Template method pattern" href="http://en.wikipedia.org/wiki/Template_method_pattern">Template method</a> defines the skeleton of an algorithm as an abstract class, allowing its subclasses to provide concrete behavior.</li>
<li><a title="Visitor pattern" href="http://en.wikipedia.org/wiki/Visitor_pattern">Visitor</a> separates an algorithm from an object structure by moving the hierarchy of methods into one object.</li>
</ul>
<h2><span class="mw-headline">Concurrency patterns</span></h2>
<p><a title="Active Object" href="http://en.wikipedia.org/wiki/Active_Object">Active Object</a>: The Active Object design pattern decouples method execution from method invocation that reside in their own thread of control. The goal is to introduce concurrency, by using asynchronous method invocation and a scheduler for handling requests.</p>
<p><a title="Balking pattern" href="http://en.wikipedia.org/wiki/Balking_pattern">Balking</a>: The Balking pattern is a software design pattern that only executes an action on an object when the object is in a particular state.</p>
<p><a class="mw-redirect" title="Double checked locking pattern" href="http://en.wikipedia.org/wiki/Double_checked_locking_pattern">Double checked locking</a> : Double-checked locking is a software design pattern also known as "double-checked locking optimization". The pattern is designed to reduce the overhead of acquiring a lock by first testing the locking criterion (the 'lock hint') in an unsafe manner; only if that succeeds does the actual lock proceed.</p>
<p>The pattern, when implemented in some language/hardware combinations, can be unsafe. It can therefore sometimes be considered to be an anti-pattern.</p>
<p><a title="Guarded suspension" href="http://en.wikipedia.org/wiki/Guarded_suspension">Guarded</a> In concurrent programming, guarded suspension is a software design pattern for managing operations that require both a lock to be acquired and a precondition to be satisfied before the operation can be executed.</p>
<p><a title="Monitor (synchronization)" href="http://en.wikipedia.org/wiki/Monitor_%28synchronization%29">Monitor object</a> A monitor is an approach to synchronize two or more computer tasks that use a shared resource, usually a hardware device or a set of variables.</p>
<p><a class="mw-redirect" title="Read write lock pattern" href="http://en.wikipedia.org/wiki/Read_write_lock_pattern">Read write lock</a> A read/write lock pattern or simply RWL is a software design pattern that allows concurrent read access to an object but requires exclusive access for write operations.</p>
<p><a title="Scheduler pattern" href="http://en.wikipedia.org/wiki/Scheduler_pattern">Scheduler</a> The scheduler pattern is a software design pattern. It is a concurrency pattern used to explicitly control when threads may execute single-threaded code.</p>
<p><a title="Thread pool pattern" href="http://en.wikipedia.org/wiki/Thread_pool_pattern">Thread pool</a> In the thread pool pattern in programming, a number of threads are created to perform a number of tasks, which are usually organized in a queue. Typically, there are many more tasks than threads.</p>
<p><a class="mw-redirect" title="Thread-Specific Storage" href="http://en.wikipedia.org/wiki/Thread-Specific_Storage">Thread-specific storage</a> Thread-local storage (TLS) is a computer programming method that uses static or global memory local to a thread.</p>
<p><a title="Reactor pattern" href="http://en.wikipedia.org/wiki/Reactor_pattern">Reactor</a> The reactor design pattern is a concurrent programming pattern for handling service requests delivered concurrently to a service handler by one or more inputs. The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[التعامل مع الاخطاء في البرمجة الكائنية : الفئة ExecutionCondition مثالاً]]></title>
<link>http://alnabhani.wordpress.com/?p=37</link>
<pubDate>Tue, 22 Jul 2008 03:37:56 +0000</pubDate>
<dc:creator>alnabhani</dc:creator>
<guid>http://alnabhani.wordpress.com/?p=37</guid>
<description><![CDATA[يعد اسلوب البرمجة الكانئية افضل اسلوب برمجي تطبقه في م]]></description>
<content:encoded><![CDATA[<p dir="rtl">يعد اسلوب البرمجة الكانئية افضل اسلوب برمجي تطبقه في معظم اللغات الحديثة والقوية وخصوصا لغات الدوت نت سواء كانت VB.Net او C# ، وعندما تطبق هذا الاسلوب فمن الاكيد بانك ستقوم ببناء فئات Classes وستحتوي بداخلها على اعضاء Members كـ Properties,Function,Subs وغيرها ، ثم تستخدم هذه الفئات في أي جزء رئيسي من الرنامج بإنشاء كائن جديد منها ثم اسناد القيم والخصائص إليه من خلال المشيد Constructor في حالة وجوده او من خلال الخصائص القابلة للكتابة Writable Properties او لاشيء من هذا !</p>
<p dir="rtl">لاحقا وبعد ان تكتب الاكواد داخل الأعضاء الخاصة بفئتك التي انشاتها للتو واللحظة ، فإنك قد تتساءل حول عملية قنص الاستثناءات Exceptions ، فماذا لو حدث استثناء معين او خطاء وقت التنفيذ في الكود ؟ هذا ما سنناقشه هنا .</p>
<p dir="rtl"><!--more--></p>
<p dir="rtl">لنفترض انك قد قمت بعمل فئة بالإسم MyData والتي تمثل بيانات شخصيه معينه يتم اسنادها لها ،كالخصائص التالية مثلا : FirstName,FamilyName,Age  ، بحيث صارت كالتالي :</p>
<p dir="rtl">
<table dir="rtl" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="568" valign="top">
<p dir="ltr">Public Class MyData</p>
<p dir="ltr">    Dim _FirstName As String</p>
<p dir="ltr">    Public Property FirstName() As String</p>
<p dir="ltr">        Get</p>
<p dir="ltr">            Return _FirstName</p>
<p dir="ltr">        End Get</p>
<p dir="ltr">        Set(ByVal value As String)</p>
<p dir="ltr">            _FirstName = value</p>
<p dir="ltr">        End Set</p>
<p dir="ltr">    End Property</p>
<p dir="ltr"> </p>
<p dir="ltr">    Dim _FamilyName As String</p>
<p dir="ltr">    Public Property FamilyName() As String</p>
<p dir="ltr">        Get</p>
<p dir="ltr">            Return _FamilyName</p>
<p dir="ltr">        End Get</p>
<p dir="ltr">        Set(ByVal value As String)</p>
<p dir="ltr">            _FamilyName = value</p>
<p dir="ltr">        End Set</p>
<p dir="ltr">    End Property</p>
<p dir="ltr"> </p>
<p dir="ltr">    Dim _Age As Byte</p>
<p dir="ltr">    Public Property Age()</p>
<p dir="ltr">        Get</p>
<p dir="ltr">            Return _Age</p>
<p dir="ltr">        End Get</p>
<p dir="ltr">        Set(ByVal value)</p>
<p dir="ltr">            _Age = value</p>
<p dir="ltr">        End Set</p>
<p dir="ltr">    End Property</p>
<p dir="ltr"> </p>
<p dir="ltr">End Class</p>
</td>
</tr>
</tbody>
</table>
<p dir="rtl"> ثم طلبت منك ان تضيف لهذه الفئة طريقة Method تقوم بكتابة البيانات الى ملف - وذلك بإضافتها الى بيانات اخرى موجودة سابقا- لتكتب الاسم الاول والعائلة والعمر ، ولنفترض - واقول نفترض- انك كتبت الكود التالي بالضبط ( بما فيه من اخطاء فادحة ! ) :</p>
<p dir="rtl">
<table dir="rtl" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="568" valign="top">
<p dir="ltr">    Public Sub WriteDataToFile(ByVal FileName As String)</p>
<p dir="ltr">        Dim FileContent As String</p>
<p dir="ltr">        FileContent = "الإسم الأول : " &#38; Me.FirstName &#38; " العائلة : " &#38; Me.FamilyName &#38; " العمر " &#38; Me.Age</p>
<p dir="ltr"> </p>
<p dir="ltr">        My.Computer.FileSystem.WriteAllText(FileName, FileContent, True)</p>
<p dir="ltr"> </p>
<p dir="ltr"> </p>
<p dir="rtl" align="right">    End Sub</p>
</td>
</tr>
</tbody>
</table>
<p dir="rtl"> </p>
<p dir="rtl">الآن لو قمنا بإنشاء كائن جديد من هذه الفئة واعطيناه قيما لخصائصه وطلبنا من الكائن ان يتكرم علينا بتنفيذ الطريقة WriteDataToFile واعطيناه الوسيط المناسب كالتالي :</p>
<p dir="rtl">
<table dir="rtl" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="568" valign="top">
<p dir="ltr">Module Module1</p>
<p dir="ltr"> </p>
<p dir="ltr">    Sub Main()</p>
<p dir="ltr"> </p>
<p dir="ltr">        Dim Mohammed As New MyData</p>
<p dir="ltr">        Mohammed.FirstName = "Mohammed"</p>
<p dir="ltr">        Mohammed.FamilyName = "AL-Nabhani"</p>
<p dir="ltr">        Mohammed.Age = 20</p>
<p dir="ltr"> </p>
<p dir="ltr">        Mohammed.WriteDataToFile("C:\Users\Personals\Documents\MyData.txt")</p>
<p dir="ltr"> </p>
<p dir="ltr">        Console.ReadLine()</p>
<p dir="ltr"> </p>
<p dir="ltr">    End Sub</p>
<p dir="ltr"> </p>
<p dir="ltr">End Module</p>
</td>
</tr>
</tbody>
</table>
<p dir="rtl"> </p>
<p dir="rtl">ثم قمنا بتجربة البرنامج ، لكن مهلا هناك استثناء وارد بنسبه كبيرة جدا وهو ان الملف MyData غير موجود ! قد تفكر بان عملية التحقق من وجود الملف اولا افضل وانا اتفق معك في ذلك تماما ، لكن ما هي سيناريوهات العملية القادمة ؟ اذا لم يجد الملف ماذا يفعل البرنامج ؟</p>
<p dir="rtl"> </p>
<p dir="rtl">في حالتي لا اريد انشاء ملف لانني اريد ان اضيف البيانات الى الملف MyData لا أن أققوم بإنشاءه في حالة عدم وجودة ، لذلك فإننا نرغب الآن بإعلام المستخدم بأن الملف غير موجود واجزم انك تتفق معي الان في ذلك ، لكن السؤال كيف سنخبر المستخدم بذلك ؟ ان كنت ستقول لنكتب سطرا مثل التالي في الطريقة المعنية :</p>
<p dir="rtl">
<table dir="rtl" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="568" valign="top">
<p dir="ltr">    Public Sub WriteDataToFile(ByVal FileName As String)</p>
<p dir="ltr">        Dim FileContent As String</p>
<p dir="ltr">        FileContent = "الإسم الأول : " &#38; Me.FirstName &#38; " العائلة : " &#38; Me.FamilyName &#38; " العمر " &#38; Me.Age</p>
<p dir="ltr"> </p>
<p dir="ltr">        If My.Computer.FileSystem.FileExists(FileName) = True Then</p>
<p dir="ltr">            My.Computer.FileSystem.WriteAllText(FileName, FileContent, True)</p>
<p dir="ltr">        Else</p>
<p dir="ltr">            Console.Write("الملف غير موجود")</p>
<p dir="ltr">        End If</p>
<p dir="ltr"> </p>
<p dir="ltr">    End Sub</p>
</td>
</tr>
</tbody>
</table>
<p dir="rtl"> </p>
<p dir="rtl">فسأقول لك ان الطريقة السابقة خاطئة تماما ، صحيح انها ستعطينا الناتج النهائي المطلوب كما قد تشتهيه ، ولكن في في اسلوب البرمجة الكائنيه ذلك خطأ ، فالمفترض ان الفئة التي انشاناها لا تعرض شيء على الشاشة بدون اذن الطريقة Main ، وافرض او اننا اردنا استخدام هذه الفئة في مشروع من نوع WIndowsApplication بدل ConsoleApplication فماذا ستفعل ؟ الادهى لو قمت بترجمه الفئة الى ملف Dll فكيف ستعرف نوع المشروع الحالي ؟ حتى لو عرفت من خلال الكود فهل يعجبك ان تكتب جملة شرطية للتأكد من نوع المشروع ثم اظهار رسالة الخطأ بالطريقة الخاصة بكل واحد ؟</p>
<p dir="rtl"> </p>
<p dir="rtl">اتمنى انك اقتنعت بذلك ، اما الحل فسيكون بتعديل الطريقة WriteDataToFile لتكون  دالة Function بدل Sub وجعلها تعود بقيمة معينه ، طيب فكر معي ، ما هو النوع Type الخاص بهذه الدالة function والتي ستعيده ؟ هل ستعيد Boolean لنعرف ان حدث خطأ ام لا ؟ ام تعيد String في كل مرة ام أي نوع ؟ طيب لنفكر في كل واحدة على حده :</p>
<p dir="rtl"> </p>
<ul>
<li>1- النوع Boolean : فكرة جيدة ، لجعل الدالة تعيد قيمة True ان تم تنفيذها كما يجب ، و False في الحالة المعاكسه ولكن يعيبها عدم اعادتها لرسالة الخطأ ، ففي حالة امكانية حدوث اكثر من خطأ واحد فهناك ستواجه مشكلة حول أي رسالة خطأ ستعرض او أي اجراء ستنفذ .</li>
<li>2- النوع String : طريقة جيدة نوعا ما ، لكن لو اردت كتابة دالة تعيد نوع معينا مثلا تقرأ ملفا معينا وتعيد الاسم الاول فكيف ستعرف ان ما اعادته هو الاسم الاول او رسالة الخطأ ؟</li>
</ul>
<p dir="rtl">لا تقل لي لنضع Field ( حقل ) عام على مستوى المشروع بمثابته متغير من النوع Boolean يعرف اذا حدث خطا ام لا فهذه الطريقة تنتهك OOP من كل النواحي !</p>
<p dir="rtl"> </p>
<p dir="rtl">طيب ما الحل اذا ؟</p>
<p dir="rtl">الحل يتم بعمل نوع جديد خاص بنا لمثل هذه الحالات ، وهو عمل فئة Class تحمل خاصية تخبرنا ان حدث خطا او لا ، وتعطينا ايضا نص رسالة الخطأ او حتى كائن الـ Error بأكمله او أي شيء من هذا القبيل ... كما قد نطورها اكثر لتحمل قيمة ما تود ارجاعه كما في الحالة الثانية اعلاه ، وهو الحل الذي سأتبعه في هذا النطاق مع انه قد يوجد حلول افضل ولكن ذلك يعتمد على الحالات التي تواجهها في برامجك .</p>
<p dir="rtl"> </p>
<p dir="rtl">الفئة الجديدة والتي سنعول عليها معرفة حدوث خطأ وحمل قيمة ناتج عملياتنا اسميتها ExecutionCondition وستحمل الخصائص التالية :</p>
<ul>
<li>HasErrors : وهي خاصية للقراءة فقط ReadOnly ومن النوع Boolean</li>
<li>ErrorMessage : وهي خاصية للقراءة فقط ايضا ومن النوع Strign</li>
<li>Value : وهي خاصية اختيارية لك ، وهي من النوع Object .</li>
</ul>
<p dir="rtl"> </p>
<p dir="rtl">بالنسبة للطرق فقد وضعت اجرائين فقط :</p>
<ul>
<li>SetErrorMessage : وهو الذي نستخدمه في اعطاء الخاصية ErrorMessage قيمتها وبناءا عليه تتحدد قمية الخاصية HasErrors .</li>
<li>Reset : يعيد الكائن الى حالته الاساسية أي بدون خطأ مع عدم المساس بقيمة الكائن المتمثل في الخاصية Value .</li>
</ul>
<p dir="rtl"> </p>
<p dir="rtl">لن اقوم بشرح كل شيء في هذه الفئة ، فهي واضحة وضوح الشمس لكل من لديه اساسيات ولو بسيطة في OOP :</p>
<p dir="rtl">
<table dir="rtl" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="568" valign="top">
<p dir="ltr">''' &#60;summary&#62;</p>
<p dir="ltr">''' This class is used to return an object with value and error message when error occur</p>
<p dir="ltr">''' &#60;/summary&#62;</p>
<p dir="ltr">''' &#60;remarks&#62;&#60;/remarks&#62;</p>
<p dir="ltr">Public Class ExecutionCondition</p>
<p dir="ltr">#Region "Properties"</p>
<p dir="ltr">    Dim _HasErrors As Boolean</p>
<p dir="ltr">    ''' &#60;summary&#62;</p>
<p dir="ltr">    ''' Determines if the assosiated process has an errors while executing it</p>
<p dir="ltr">    ''' &#60;/summary&#62;</p>
<p dir="ltr">    ''' &#60;value&#62;&#60;/value&#62;</p>
<p dir="ltr">    ''' &#60;returns&#62;&#60;/returns&#62;</p>
<p dir="ltr">    ''' &#60;remarks&#62;&#60;/remarks&#62;</p>
<p dir="ltr">    Public ReadOnly Property HasErrors() As Boolean</p>
<p dir="ltr">        Get</p>
<p dir="ltr"> </p>
<p dir="ltr">            Return _HasErrors</p>
<p dir="ltr">            If Me._HasErrors = True Then Me._ErrorMessage = ""</p>
<p dir="ltr">        End Get</p>
<p dir="ltr">    End Property</p>
<p dir="ltr"> </p>
<p dir="ltr">    Dim _ErrorMessage As String</p>
<p dir="ltr">    ''' &#60;summary&#62;</p>
<p dir="ltr">    ''' Gets the error message if the assisiated process has an erors while executing</p>
<p dir="ltr">    ''' &#60;/summary&#62;</p>
<p dir="ltr">    ''' &#60;value&#62;&#60;/value&#62;</p>
<p dir="ltr">    ''' &#60;returns&#62;&#60;/returns&#62;</p>
<p dir="ltr">    ''' &#60;remarks&#62;&#60;/remarks&#62;</p>
<p dir="ltr">    Public ReadOnly Property ErrorMessage() As String</p>
<p dir="ltr">        Get</p>
<p dir="ltr">            Return _ErrorMessage</p>
<p dir="ltr">        End Get</p>
<p dir="ltr"> </p>
<p dir="ltr">    End Property</p>
<p dir="ltr"> </p>
<p dir="ltr">    Dim _Value As Object</p>
<p dir="ltr">    ''' &#60;summary&#62;</p>
<p dir="ltr">    ''' Represents the value of the ibject, it could be any type .</p>
<p dir="ltr">    ''' &#60;/summary&#62;</p>
<p dir="ltr">    ''' &#60;value&#62;&#60;/value&#62;</p>
<p dir="ltr">    ''' &#60;returns&#62;&#60;/returns&#62;</p>
<p dir="ltr">    ''' &#60;remarks&#62;&#60;/remarks&#62;</p>
<p dir="ltr">    Public Property Value() As Object</p>
<p dir="ltr">        Get</p>
<p dir="ltr">            Return _Value</p>
<p dir="ltr">        End Get</p>
<p dir="ltr">        Set(ByVal value As Object)</p>
<p dir="ltr">            _Value = value</p>
<p dir="ltr">        End Set</p>
<p dir="ltr">    End Property</p>
<p dir="ltr">#End Region</p>
<p dir="ltr"> </p>
<p dir="ltr">#Region "Methods"</p>
<p dir="ltr"> </p>
<p dir="ltr">    Public Sub New()</p>
<p dir="ltr"> </p>
<p dir="ltr">    End Sub</p>
<p dir="ltr">    ''' &#60;summary&#62;</p>
<p dir="ltr">    ''' Sets the Error Message</p>
<p dir="ltr">    ''' &#60;/summary&#62;</p>
<p dir="ltr">    ''' &#60;param name="Message"&#62;"the message of the error that will be presented in Error Message property&#60;/param&#62;</p>
<p dir="ltr">    ''' &#60;remarks&#62;&#60;/remarks&#62;</p>
<p dir="ltr">    Public Sub SetErrorMessage(ByVal Message As String)</p>
<p dir="ltr">        _ErrorMessage = Message</p>
<p dir="ltr">        _HasErrors = True</p>
<p dir="ltr">    End Sub</p>
<p dir="ltr">    ''' &#60;summary&#62;</p>
<p dir="ltr">    ''' resets the object so no errors are contained</p>
<p dir="ltr">    ''' &#60;/summary&#62;</p>
<p dir="ltr">    ''' &#60;remarks&#62;&#60;/remarks&#62;</p>
<p dir="ltr">    Public Sub Reset()</p>
<p dir="ltr">        Me._HasErrors = False</p>
<p dir="ltr"> </p>
<p dir="ltr">    End Sub</p>
<p dir="ltr">#End Region</p>
<p dir="ltr">End Class</p>
</td>
</tr>
</tbody>
</table>
<p dir="rtl"> </p>
<p dir="rtl">الآن لنقم بعمل مثال عملي جديد لنجرب استخدام هذه الفئة ، اما بخصوص مثالنا السابق والفئة MyData فاعتبره تمرينا لك لحل مشكلتنا الأساسية !</p>
<p dir="rtl"> </p>
<p dir="rtl">في الوحدة النمطية Module1 التي تحتوي على الطريقة Main - الجزء الاساسي من البرنامج بطبيعة الحال - فقد قمت باضافة الدالة التالية فيها :</p>
<p dir="rtl">
<table dir="rtl" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="568" valign="top">
<p dir="ltr">    Function WriteOnTheScreen() As ExecutionCondition</p>
<p dir="ltr">        Dim mExCn As New ExecutionCondition</p>
<p dir="ltr"> </p>
<p dir="ltr">        Try</p>
<p dir="ltr">            Console.WriteLine(5 / 1)</p>
<p dir="ltr">            Console.ReadLine()</p>
<p dir="ltr"> </p>
<p dir="ltr">            mExCn.Reset()</p>
<p dir="ltr"> </p>
<p dir="ltr">        Catch ex As Exception</p>
<p dir="ltr">            mExCn.SetErrorMessage(ex.Message)</p>
<p dir="ltr">        End Try</p>
<p dir="ltr"> </p>
<p dir="ltr">        Return mExCn</p>
<p dir="ltr">    End Function</p>
</td>
</tr>
</tbody>
</table>
<p dir="rtl"> </p>
<p dir="rtl">وفي الطريقة Main كتبت الكود التالي :</p>
<p dir="rtl">
<table dir="rtl" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="568" valign="top">
<p dir="ltr">    Sub Main()</p>
<p dir="ltr">        'لنجرب تنفيذ الدالة</p>
<p dir="ltr">        'WriteOnTheScreen</p>
<p dir="ltr">        If WriteOnTheScreen.HasErrors = True Then</p>
<p dir="ltr">            Console.WriteLine(WriteOnTheScreen.ErrorMessage)</p>
<p dir="ltr">        End If</p>
<p dir="ltr">        Console.ReadLine()</p>
<p dir="ltr">    End Sub</p>
</td>
</tr>
</tbody>
</table>
<p dir="rtl"> </p>
<p dir="rtl">بعد تشغيل البرنامج سيظهر كل شيء على ما يرام هذه المرة وسيطبع 5 ، لنجرب الآن تعديل الطريقة WriteOnTheScreen ولنجعل القسمة مبنية على صفر وهذا خطأ رياضي فادح جدا :</p>
<p dir="rtl">
<table dir="rtl" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="568" valign="top">
<p dir="ltr">    Function WriteOnTheScreen() As ExecutionCondition</p>
<p dir="ltr">        Dim mExCn As New ExecutionCondition</p>
<p dir="ltr"> </p>
<p dir="ltr">        Try</p>
<p dir="ltr"> </p>
<p dir="ltr">            Dim x As Integer = 5</p>
<p dir="ltr">            Dim y As Integer = 0</p>
<p dir="ltr">            Dim z As Integer = x / y</p>
<p dir="ltr">            Console.WriteLine(z)</p>
<p dir="ltr">            Console.ReadLine()</p>
<p dir="ltr"> </p>
<p dir="ltr">            mExCn.Reset()</p>
<p dir="ltr"> </p>
<p dir="ltr">        Catch ex As Exception</p>
<p dir="ltr">            mExCn.SetErrorMessage(ex.Message)</p>
<p dir="ltr">        End Try</p>
<p dir="ltr"> </p>
<p dir="ltr">        Return mExCn</p>
<p dir="ltr">    End Function</p>
<p dir="ltr"> </p>
</td>
</tr>
</tbody>
</table>
<p dir="rtl"> </p>
<p dir="rtl">الآن قم بتنفيذ البرنامج ولاحظ ماسيحدث ، سيطبع نص رسالة الخطأ مهما يكن نوع الخطأ الذي حدث ، سواء القسمة على صفر او أي خطأ آخر وتأكد من كلامي جيدا !</p>
<p dir="rtl"> </p>
<p dir="rtl">ختاما ارجو انني قد وفقت في لفت الانتباء الى مسألة التعامل مع الاخطاء في الكائنات المستقلة واذا وجد هنا أي خطأ فأرجو تنبيهي عليه وجل من لا يسهو .</p>
<p dir="rtl"> </p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[C# .NET Generics: Nested Types]]></title>
<link>http://shiman.wordpress.com/?p=103</link>
<pubDate>Sun, 20 Jul 2008 10:36:06 +0000</pubDate>
<dc:creator>shiman</dc:creator>
<guid>http://shiman.wordpress.com/?p=103</guid>
<description><![CDATA[You can nest a generic type inside a nongeneric type. Conversely, a nongeneric type can be nested in]]></description>
<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">You can nest a generic type inside a nongeneric type. Conversely, a nongeneric type can be nested in a generic type. More intriguing is nesting generic types inside of generic types. The nested generic type can consume the type parameters of the surrounding type. A type </span><a name="595"></a><a name="IDX-260"></a><span style="font-size:small;font-family:Calibri;">parameter of the surrounding type cannot be redefined as a new type parameter in the nested type. However, the nested generic type can declare entirely new type parameters.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">This is sample code of nested generic types:</span></p>
<table class="MsoTableGrid" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:6.65in;background-color:transparent;border:black 1pt solid;padding:0 5.4pt;" width="638" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:Consolas;">using</span><span style="font-size:10pt;font-family:Consolas;"> System;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:Consolas;">namespace</span><span style="font-size:10pt;font-family:Consolas;"> Examples.Generics</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Program</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> Main()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span><span style="color:#2b91af;">ZClass</span>&#60;<span style="color:blue;">int</span>&#62;.<span style="color:#2b91af;">Nested</span>&#60;<span style="color:blue;">double</span>&#62; obj =</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>                </span><span style="color:blue;">new</span> <span style="color:#2b91af;">ZClass</span>&#60;<span style="color:blue;">int</span>&#62;.<span style="color:#2b91af;">Nested</span>&#60;<span style="color:blue;">double</span>&#62;();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>            </span>obj.MethodA(10, 12.34);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Consolas;