<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>41 technologies &#187; .Net</title>
	<atom:link href="http://techblog.41concepts.com/category/microsoft/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.41concepts.com</link>
	<description>A software development blog from 41concepts</description>
	<lastBuildDate>Fri, 25 Nov 2011 14:44:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='techblog.41concepts.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>41 technologies &#187; .Net</title>
		<link>http://techblog.41concepts.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://techblog.41concepts.com/osd.xml" title="41 technologies" />
	<atom:link rel='hub' href='http://techblog.41concepts.com/?pushpress=hub'/>
		<item>
		<title>Breaking encapsulation with C# 2.0 partial classes (moved posting)</title>
		<link>http://techblog.41concepts.com/2010/03/23/breaking-encapsulation-with-c-2-0-partial-classes-moved-posting/</link>
		<comments>http://techblog.41concepts.com/2010/03/23/breaking-encapsulation-with-c-2-0-partial-classes-moved-posting/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 17:03:30 +0000</pubDate>
		<dc:creator>mmc</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[CopyFromOldBlog]]></category>

		<guid isPermaLink="false">http://techblog.41concepts.com/?p=61</guid>
		<description><![CDATA[For good or bad partial classes in C# 2.0 allows breaking of encapsulation as this example will show. In a consulting job I recently ran into an interesting case involving a webservice with several different service methods f1, f2, fn (sample names, not actual names) all taking the same string argument and all returning a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techblog.41concepts.com&amp;blog=1325376&amp;post=61&amp;subd=41tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For good  or bad <a href="http://en.wikipedia.org/wiki/Partial_type">partial  classes</a> in C# 2.0 allows breaking of encapsulation as this example  will show.</p>
<p>In a  consulting job I recently ran into an interesting case involving a  webservice with several different service methods f1, f2, fn <em>(sample  names, not actual names)</em> all taking the same string argument and  all returning a string. The user would select an operation name after  which my code had to call the named operation on a web service using a  standard parameter. Trivial really, if one would do accept bad code like  this below, but I don’t:</p>
<p><code> </code></p>
<pre><em> String operationName = …
 String arg = …
 Webserviceproxy webserviceproxy = …
 // Warning: Badly coupled code begins here (need to update each time we  add/rename/delete operations).
 switch (operationName) {
 case “f1″: return webserviceproxy.f1(arg); break;
 case “f2″: return webserviceproxy.f2(arg); break;
 }</em>
</pre>
<p>What is  really needed is a method to invoke a webservice method by name, while  still using the generated .NET proxy to do the hard soap/http stuff (no  time to reinvent a better wheel here). Reflection is one way to do this, but let&#8217;s try another type-safe method for this posting, because the technique shown here is quite powerful for all sorts of related problems:</p>
<p>Let’s look at an extract  of the generated proxy:</p>
<p><code> </code></p>
<pre><em>public partial class Webserviceproxy :  System.Web.Services.Protocols.SoapHttpClientProtocol
 {
  …
  public string f1(string arg) {
   object[] results = this.Invoke(”f1″, new object[] {arg});
   return ((string)(results[0]));
  }
  …
 }</em></pre>
<p>and at  the inherited SoapHttpClientProtocol:</p>
<p><code> </code></p>
<pre> <em>public  class SoapHttpClientProtocol : HttpWebClientProtocol {</em>
 <em> …</em>
 <em> protected object[]  Invoke(string methodName, object[] parameters) {</em>
 <em> …</em>
 <em> }</em>
 <em> …</em></pre>
<pre> <em> }</em></pre>
<p>It  seems the method “invoke” would fulfil our needs if it was only public  (which it isn’t). So what do we do? Certainly we do not want to modify  the generated file (and lose our changes each time it is regenerated).</p>
<p>The  good news is that Generatedwebserviceproxy is a partial class so we can  extend it with the following code. We will place the code in a file  safely outside the generated proxy class file:</p>
<p><code> </code></p>
<pre><em>public partial class Webserviceproxy :  System.Web.Services.Protocols.SoapHttpClientProtocol
 {
  ///
  /// Dynamic operation that allows us to call an operation by name.
  ///
  public string InvokeAny(String operationName, string arg)
  {
   object[] results = this.Invoke(operationName, new object[] {arg});
   return ((string)(results[0]));
  }
 }</em></pre>
<p>The  compiler will merge the two class definitions effectively adding a new  public InvokeAny method to the generated class. And now we can call our  web service calls dynamicly from using InvokeAny:</p>
<p><code> </code></p>
<pre><em> String operationName = …
 String arg = …
 Webserviceproxy webserviceproxy = …
 return webserviceproxy.InvokeAny(operationName, arg);</em></pre>
<p>Clearly,  easy to do and with better overall code than a “switch” &#8211; even though  it is not without drawbacks as it breaks encapsulation of the generated  proxy.</p>
<p><strong>Post scriptum:</strong><br />
Used the same partial  classes trick today to add a common custom interface to two differently  generated proxies. I now officially miss this feature in Java (yes, <a href="http://www.eclipse.org/aspectj/">AspectJ </a>can do the thing but  it is not a official part of the language).</p>
<p><strong>Recent update and notice:</strong></p>
<p>This post an almost identical copy from my old blog at &#8220;<a href="http://www.mortench.net/blog/2006/05/03/breaking-encapsulation-with-c-20-partial-classes/" target="_blank">http://www.mortench.net/blog</a>&#8221; which I will shortly retire for good.</p>
<br />Filed under: <a href='http://techblog.41concepts.com/category/microsoft/net/'>.Net</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/41tech.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/41tech.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/41tech.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/41tech.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/41tech.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/41tech.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/41tech.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/41tech.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/41tech.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/41tech.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/41tech.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/41tech.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/41tech.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/41tech.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techblog.41concepts.com&amp;blog=1325376&amp;post=61&amp;subd=41tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techblog.41concepts.com/2010/03/23/breaking-encapsulation-with-c-2-0-partial-classes-moved-posting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d5bb3e48385cef486d4d915f9713e49b?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">mmc</media:title>
		</media:content>
	</item>
		<item>
		<title>Asp.net MVC framework</title>
		<link>http://techblog.41concepts.com/2007/10/12/aspnet-mvc-framework/</link>
		<comments>http://techblog.41concepts.com/2007/10/12/aspnet-mvc-framework/#comments</comments>
		<pubDate>Fri, 12 Oct 2007 06:49:49 +0000</pubDate>
		<dc:creator>Rasmus</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://techblog.41concepts.com/2007/10/12/aspnet-mvc-framework/</guid>
		<description><![CDATA[And so it happened&#8230; Microsoft acknowledged that not all developers like the whole event driven/viewstate model. Other web frameworks like the MVC model has been used for years on other platforms, alternatives like MonoRails have existed on the .net platform with a small loyal crowd of developers. But now&#8230;. (my guess is because the whole [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techblog.41concepts.com&amp;blog=1325376&amp;post=14&amp;subd=41tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>And so it happened&#8230; Microsoft <span>acknowledged</span> that not all developers like the whole event driven/viewstate model.</p>
<p>Other web frameworks like the MVC model has been used for years on other platforms, alternatives like <a href="http://www.castleproject.org/monorail/">MonoRails</a> have existed on the .net platform with a small loyal crowd of developers.</p>
<p>But now&#8230;. (my guess is because the whole buzz about <a href="http://www.rubyonrails.com" target="_blank">Ruby on Rails</a> and its MVC model) Microsoft launches their own MVC framework:</p>
<p><span></span> <a href="http://codebetter.com/blogs/jeffrey.palermo/archive/2007/10/05/altnetconf-scott-guthrie-announces-asp-net-mvc-framework-at-alt-net-conf.aspx">http://codebetter.com/blogs/jeffr&#8230;mvc-framework-at-alt-net-conf.aspx</a></p>
<p>At last&#8230; I can&#8217;t wait to try it out and to see how adoption  goes.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/41tech.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/41tech.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/41tech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/41tech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/41tech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/41tech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/41tech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/41tech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/41tech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/41tech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/41tech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/41tech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/41tech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/41tech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/41tech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/41tech.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techblog.41concepts.com&amp;blog=1325376&amp;post=14&amp;subd=41tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techblog.41concepts.com/2007/10/12/aspnet-mvc-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee17bd3edd1c0a865a3302c1de2f2e79?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rasmus</media:title>
		</media:content>
	</item>
		<item>
		<title>Shooting yourself in the leg with a bazooka</title>
		<link>http://techblog.41concepts.com/2007/07/13/shooting-yourself-in-the-leg-with-a-bazooka/</link>
		<comments>http://techblog.41concepts.com/2007/07/13/shooting-yourself-in-the-leg-with-a-bazooka/#comments</comments>
		<pubDate>Fri, 13 Jul 2007 21:11:13 +0000</pubDate>
		<dc:creator>mmc</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Design & Architecture]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://techblog.41concepts.com/2007/07/13/shooting-yourself-in-the-leg-with-a-bazooka/</guid>
		<description><![CDATA[The colorful title reflects that this posting is about common mistakes done by good but relatively inexperienced software developers. Big mistakes that a developer actually need quite some skills to make. Mistakes that we unfortunately see all too often and we would rather not see much of again (hopefully this blog entry can aid a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techblog.41concepts.com&amp;blog=1325376&amp;post=4&amp;subd=41tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <font color="#ff0000">colorful </font>title reflects that this posting is about common <strong>mistakes done by good </strong>but relatively<strong> </strong>inexperienced <strong>software developers</strong>. Big mistakes that a developer actually need quite some skills to make. Mistakes that we unfortunately see all too often and we would rather not see much of again (hopefully this blog entry can aid a bit towards that goal):</p>
<ol>
<li><strong>Overly complicated design</strong> – Instead of a simple design for a simple project some developers insist on using a impracticable mix of all the newest, fanciest abstractions, <a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)" title="Wiki article">design patterns</a>, techniques and advanced language constructs that can possibly be combined in one software solution. All design elements have benefits and drawbacks. Great (experienced) developers know when a particular benefit of an abstraction, pattern, technique or feature outweighs the drawbacks. There is <a href="http://en.wikipedia.org/wiki/No_Silver_Bullet" title="Wiki article">no silver bullet</a>. No design element works well in all situations (just as no rules that you learned in “programming school” are in fact absolute). Developers that get way too eager ends up with one big unmaintainable design mess with the combined drawbacks of all decisions but few if any real benefits remaining…. Remember, a simple design is a beautiful design!</li>
<li><strong>Writing too much code</strong> – Writing lengthily code with a high maintenance cost by hand when writing such code can be avoided. Much code can be avoided by choosing a more suitable design/architecture, using standard framework/library features (xml serialization is a common example), using techniques such as dynamic <a href="http://en.wikipedia.org/wiki/Reflection_%28computer_science%29" title="Wiki article">reflection</a> or specialized <a href="http://www.codegeneration.net/" title="Code generation site">code generation</a> and <a href="http://aosd.net/wiki/index.php?title=Tools_for_Developers" title="Wiki article">aspect oriented tools</a> (be careful though).</li>
<li><strong>Reinventing the wheel</strong>  &#8211; Some developers think they can write their own code much faster than learning to understand the underlying framework and available libraries. This might in some cases even be true, but when considering overall quality and maintainability (which developers seldom do) <a href="http://en.wikipedia.org/wiki/Reinventing_the_wheel" title="Wiki article">reinventing the wheel</a> is almost always a bad idea.</li>
<li><strong>Incorrect use of advanced concepts such as multithreading</strong> – Some developers use <a href="http://en.wikipedia.org/wiki/Multithreading" title="Wiki article">multithreading </a>without the discipline and deep understanding that writing correct, <a href="http://en.wikipedia.org/wiki/Thread-safety" title="Wiki article">safe</a> multi-threaded code requires. Multithreading can<a href="http://www.manning.com/dennis/" title="Book"> improve the user experience</a> immensely. It is also the <a href="http://www.gotw.ca/publications/concurrency-ddj.htm">answer to scalability</a> nowadays. However, before even considering to use multithreading in your design, make sure to know the theory and features in your environment well. A vague recollection of <a href="http://en.wikipedia.org/wiki/Mutual_exclusion" title="Wiki article">mutexes </a>and <a href="http://http://en.wikipedia.org/wiki/Semaphore_(programming)">semaphores </a>from school is not good enough. You should also realize that by deciding to use multithreading, you generally need to upgrade on testing, documentation, reviews and quality insurance.</li>
</ol>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/41tech.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/41tech.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/41tech.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/41tech.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/41tech.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/41tech.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/41tech.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/41tech.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/41tech.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/41tech.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/41tech.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/41tech.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/41tech.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/41tech.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/41tech.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/41tech.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techblog.41concepts.com&amp;blog=1325376&amp;post=4&amp;subd=41tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techblog.41concepts.com/2007/07/13/shooting-yourself-in-the-leg-with-a-bazooka/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d5bb3e48385cef486d4d915f9713e49b?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">mmc</media:title>
		</media:content>
	</item>
	</channel>
</rss>
