<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>.NET Multiple Inheritance</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/default.aspx</link><description>Multiple Inheritance and Assorted OO Ramblings from a .NET Madman</description><dc:language>en-US</dc:language><generator>CommunityServer 1.0 (Build: 1.0.1.50214)</generator><item><title>Toronto Code Camp 2007 an Overwhelming Success</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2007/04/03/220318.aspx</link><pubDate>Tue, 03 Apr 2007 17:25:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:220318</guid><dc:creator>shayward</dc:creator><slash:comments>1</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/220318.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=220318</wfw:commentRss><description>It was &lt;a href="http://www.torontocodecamp.net/"&gt;Toronto Code Camp&lt;/a&gt; time once again and this year was a wonderful follow-up to the first Toronto Code Camp held last year. Special thanks to MVP &lt;a href="http://geekswithblogs.net/chrduf/"&gt;Chris Dufour&lt;/a&gt; for organizing this fantastic event as well as giving the best talk of the day, which was on Windows Communication Foundation.
&lt;p&gt;
It’s always a good combination between well-dressed nerds and those of us that continue to perpetuate various geek-culture stereotypes. I, for one, go with the glasses, plaid shirt, tan pants, and suspenders. I love the code camps because they are one of the rare times that I realize that I am not alone in my sense of fashion and my love of Doctor Who.
&lt;p&gt;
This year I spoke on Reflection – one of my favorite aspects of .NET (and aptly stolen from Java). Reflection allows you to discover an object’s type at runtime if you don’t already know it and query the structure of the classes. You can also invoke methods, change properties, and play with events all dynamically at runtime.
&lt;p&gt;
It’s great for creating a plug-in architecture as well as creating a generic business object validator or a generic data access layer. It’s also handy for hacking a DLL if you don’t have the source code.
&lt;p&gt;
Reflection is a fairly advanced topic and assumes good foundational knowledge of object oriented programming. My big concern was being able to communicate this topic effectively so as to open up everyone’s understanding in the course of an hour. Based on the comments I received, the mission was accomplished.
&lt;p&gt;
One thing is for certain: it is both humbling and encouraging that I have managed to travel this far in the geek’s journey to be able to impart knowledge and understanding to others. But I’m still young in the journey and have a lot of recursions to go before I either return 0 or hit a stack overflow exception.
&lt;p&gt;
Happy Coding&lt;BR&gt;
- Shaun&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=220318" width="1" height="1"&gt;</description></item><item><title>MVP: Object/Relational Hybrid Database provides More Power, Higher Data Integrity</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2006/08/04/143321.aspx</link><pubDate>Fri, 04 Aug 2006 15:25:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:143321</guid><dc:creator>shayward</dc:creator><slash:comments>0</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/143321.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=143321</wfw:commentRss><description>&lt;P&gt;In this month’s Architectural Journal there was a fantastic article by SQL Server MVP &lt;A href="http://www.sqlserverbible.com/"&gt;Paul Nielsen&lt;/A&gt; entitled &lt;A href="http://www.architecturejournal.net/2006/issue8/F6_Nordic/"&gt;The Nordic Object/Relational Database Design&lt;/A&gt;. This design basically adds &lt;A href="http://en.wikipedia.org/wiki/Object_database"&gt;OODBMS&lt;/A&gt; features on top of a &lt;A href="http://en.wikipedia.org/wiki/RDBMS"&gt;RDBMS&lt;/A&gt;, creating a hybrid with the advantages of both while simultaneously removing (most of) the disadvantages of both.&lt;/P&gt;
&lt;P&gt;It's a brilliant piece, incredibly simple, and a worth-while read for anyone that loves object-oriented and finds O/R Mappers overly-cumbersome. I have to wonder if, by day, Mr. Nielsen is really mild-mannered reporter &lt;A href="http://en.wikipedia.org/wiki/Clark_Kent"&gt;Clark Kent&lt;/A&gt;. I can hardly wait for the &lt;A href="http://www.sqlserverbible.com/ordbms.htm"&gt;book&lt;/A&gt;, due out this December. I've already asked my wife to get it for me for Christmas. (Yes, I do realize that I'm a total geek with no sense of real fun)&lt;/P&gt;
&lt;P&gt;I also find Mr. Nielsen's views a refreshing contrast to &lt;a href="http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/12/01/134096.aspx"&gt;the last SQL Server MVP with whom I spoke&lt;/A&gt;.&lt;BR&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=143321" width="1" height="1"&gt;</description></item><item><title>Multiple Inheritance: Microsoft Should Introduce Better Interface Implementation</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2006/07/14/142019.aspx</link><pubDate>Fri, 14 Jul 2006 14:35:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:142019</guid><dc:creator>shayward</dc:creator><slash:comments>0</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/142019.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=142019</wfw:commentRss><description>&lt;P&gt;A couple of days ago I &lt;a href="http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2006/07/12/141899.aspx"&gt;posted on Implementation Classes&lt;/A&gt; as a viable solution for most Multiple Inheritance benefits without actually having Multiple Inheritance. I feel very strongly that Microsoft should make Implementation Classes or something equivalent a direct part of the C# 4.0 and VB 10 languages (given that it won’t happen in Orcas). &lt;/P&gt;
&lt;P&gt;I think this would be one of the most important language developments that could ever happen in .NET. &lt;/P&gt;
&lt;P&gt;It would eliminate all of the annoying copy-and-paste code involved in implementing multiple interfaces and pointing them back to true objects to gain most of the benefits of Multiple Inheritance. Plus it would settle most of the calls for true MI and still satisfies the anti-multiple-inheritance camp.&lt;/P&gt;
&lt;P&gt;Best of all, Microsoft can easily (and I stress easily) do this with compiler wizardry given that it really isn’t a huge amount of work (just very tedious) to do it manually. If Microsoft can come up with compiler solutions for Generics, LINQ, Extension Methods, and Dynamic Typing then there is no reason to make major changes to the CLR for Implementation Classes.&lt;/P&gt;
&lt;P&gt;So what could it look like syntactically? There are a few different thoughts on this and &lt;A href="http://en.wikipedia.org/wiki/Anders_Hejlsberg"&gt;Anders Hejlsberg&lt;/A&gt; would certainly have something to say about this... at least for the C# camp. Let's take a look:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Implementation Classes&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;This is my take on it, although most of it has been liberally borrowed from other sources, to the authors of which I am eternally grateful. &lt;/P&gt;
&lt;P&gt;The trick is to create one or more special “Implementation Classes” that each provides strong implementation for one or more of the desired interfaces. Suppose we had the following interface:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public interface IEditableObject&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void BeginEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void CancelEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void EndEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;That’s not so hard to imagine because it does exist in the .NET Framework. If we want to use this interface in the exact same way with the exact same code for multiple classes then we would start by creating an “Implementation Class called EditableObject:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public implementation class EditableObject : IEditableObject&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public EditableObject ()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... Constructor Could Contain Parameters&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... Some Private Member Variables&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (Probably a Key/Object Pair)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; To Hold The Values Of Different Properties and Fields&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Captured During BeginEdit()&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp; System.ComponentModel.IEditableObject.BeginEdit()&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... Use Reflection To Store Current Values&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp; System.ComponentModel.IEditableObject.CancelEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... Use Reflection To Write Back Values&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Captured in BeginEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp; System.ComponentModel.IEditableObject.EndEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... Clear Values Captured in BeginEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Notice the implementation keyword. First of all, it would prevent the class from being instantiated directly, similar to the way that abstract does:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// The following line would not compile&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EditableObject e = new EditableObject();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;More importantly, this would tell the compiler that this is an implementation class. When another class “inherits” it, the inheritance wouldn’t be your standard, garden-variety of inheritance. Consider the Product class:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public class Product : EditableObject&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;When this compiles, it would not compile to a standard inheritance relationship. Instead, the MSIL produced would be equivalent to if we had written the following:&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public class Product : System.ComponentModel.IEditableObject&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EditableObject _EditableObjectImplementation;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp; System.ComponentModel.IEditableObject.BeginEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_EditableObjectImplementation.BeginEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp; System.ComponentModel.IEditableObject.CancelEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_EditableObjectImplementation.CancelEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void&amp;nbsp; System.ComponentModel.IEditableObject.EndEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_EditableObjectImplementation.EndEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Here I have chosen to use explicit interface implementation. That makes a great deal of sense because typically we would pass a Product object to a method expecting a reference to an IEditableObject interface. We wouldn’t usually want to directly call BeginEdit() from a Project object. For implicit interface implementation, I would simply add an implicit keyword:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public class Product : EditableObject implicit&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This would produce MSIL equivalent to:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public class Product : System.ComponentModel.IEditableObject&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EditableObject _EditableObjectImplementation;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public void&amp;nbsp; BeginEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_EditableObjectImplementation.BeginEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public void&amp;nbsp; CancelEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_EditableObjectImplementation.CancelEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public void&amp;nbsp; EndEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_EditableObjectImplementation.EndEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Obviously _ EditableObjectImplementation needs to be instantiated in the constructor so that some poor consumer of a Product object doesn’t get the dreaded null reference exception. It could be handed in a similar way to the call to base() in C# and done by using the Implementation Class’ name:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public Product()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: base(), EditableObject()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This would compile to MSIL as if we had written:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EditableObject e = new EditableObject();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;As previously stated, we wouldn’t be able to actually make the above call ourselves. If more than one implementation classes where consumed by the Product class then they should appear in the order of instantiation:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public Product()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: base(), EditableObject(), Clonable()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Parameters could be passed to each Implementation Class’ constructor if needed. Another approach would be to require the instantiation to be done within the body of the Product class’ constructor. The most flexible would be to allow the instantiation to occur anywhere in constructor body:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public Product()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: base()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... Code Here ... //&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EditableObject();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clonable();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... Code Here ... //&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This gives maximum flexibility to accomplish everything that you can already do but without having to write tedious and identical plumbing over and over and over again. If an instantiation call is not invoked in the constructor body then it should be done automatically by the compiler at the beginning of the constructor.&lt;/P&gt;
&lt;P&gt;Remember, this type of thing is already possible if you do it manually; all I’m doing here is proposing my version of the syntactic sugar that IntelliSense and the compiler could give us to make it easier and less typo-prone.&lt;/P&gt;
&lt;P&gt;Now let’s look at someone else’s idea:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Implicit Interface Implementation through Aggregation&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;While searching through Microsoft’s product feedback center for other Multiple Inheritance and Default Interface Implementation sympathizers, I came across a great idea posted by Dmitry Kolchev. &lt;/P&gt;
&lt;P&gt;See (and vote on) this wonderful idea at:&lt;BR&gt;&lt;A href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94304"&gt;http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94304&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;We will keep the same example as above as far as creating the EditableObject class (with the removal of the factious “implementation” keyword in the class definition). Dmitry’s Product class would look like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public class Product : System.ComponentModel.IEditableObject&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EditableObject _EditableObjectImplementation provides IEditableObject;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Here he is proposing a new keyword called “provides” to tell the compiler to create a member definition within Product for each of IEditableObject’s members and to point them straight back at the _EditableObjectImplementation object’s corresponding member. In essence, the compiler would be adding MSIL equivalent to if we had typed in:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public class Product : System.ComponentModel.IEditableObject&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EditableObject _EditableObjectImplementation;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public void&amp;nbsp; BeginEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_EditableObjectImplementation.BeginEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public void&amp;nbsp; CancelEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_EditableObjectImplementation.CancelEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public void&amp;nbsp; EndEdit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_EditableObjectImplementation.EndEdit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;That is the same equivalent code as my Implementation Classes idea but Dmitry has gone about the definition syntax a differently. To change between implicit and explicit implementation Dmitry has also proposed the keywords “implicit” and “explicit”, although it isn’t stated where they would be placed. My guess would be after “provides”.&lt;/P&gt;
&lt;P&gt;Also, the developer gets full control over how and when the _EditableObjectImplementation field is instantiated, which is the most flexible. Of course, if the developer doesn’t do that then they end of up with a null reference exception. The existing compiler warning will probably be enough to help most programmers and this isn’t really an issue.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Default Interface Implementation&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;Some folks are after Default Interface Implementation, in which interface definitions members have code in them and if you don’t “override” that member when you implement the interface then the code in the interface is used by default.&lt;/P&gt;
&lt;P&gt;Several years ago I thought this was a good idea but I have come to realize that it would be completely useless in the vast majority of cases. Each solution has very different needs and the chances of a 1-size-fits-all solution for an interface implementation are incredibly slim.&lt;/P&gt;
&lt;P&gt;We must have the ability to create different “default” behaviours for the same interface because your needs are different from my need and my needs in Project ABC are different than my needs in Project XYZ. Default Interface Implementation in which the code is together with the interface just doesn’t offer this.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Summary&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;I’m always been one to look for the best solution and I must say that I really like Dmitry’s solution. For one thing, it really clarifies that there is a big difference between inheritance and interface implementation. &lt;/P&gt;
&lt;P&gt;That’s something that I really like about VB – it uses the Inherits keyword for inheriting and the Implements keyword for interface implementation whereas C# makes it all look like inheritance. Granted, C# is my language of choice in part because of its slim syntax but I think that every Introduction to OOP course should be taught with VB.NET because of its clear syntax.&lt;/P&gt;
&lt;P&gt;So, Microsoft, if you’re listening: Dmitry’s idea here is fantastic and you should probably implement Default Interface Implementation this way if you don’t want the anti-Multiple-Inheritance camp up in arms. Plus it just makes a huge amount of sense. If you want to half-fake MI, go with my idea. If you want to fully-fake MI, go with what Eiffel# does. The MSIL that would be generated is the same no matter what the syntax.&lt;/P&gt;
&lt;P&gt;Regardless of how it is done, I feel very strongly that this would benefits developers everywhere – especially those of us that are writing large frameworks. For now, we can still do it manually, albeit with a lot of tedium and copy-and-paste code. Here’s hoping Hawaii makes pseudo-MI a walk on the beach.&lt;/P&gt;
&lt;P&gt;Happy Coding&lt;BR&gt;- Shaun&lt;BR&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=142019" width="1" height="1"&gt;</description></item><item><title>Multiple Inheritance Solutions: Implementation Classes</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2006/07/12/141899.aspx</link><pubDate>Wed, 12 Jul 2006 15:16:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:141899</guid><dc:creator>shayward</dc:creator><slash:comments>1</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/141899.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=141899</wfw:commentRss><description>&lt;P&gt;Getting into discussions about Multiple Inheritance can be sticky things. Single-Inheritance-purists want the perfect object pyramid starting with object as the apex. They claim that it is cleaner - and they're right. How many “is a kind of” relationships can a class have?&lt;/P&gt;
&lt;P&gt;But we must ask ourselves, "What problems are supposed to be solved by inheritance?" and then we must ask ourselves if our current or near-future system (let's say C# 3.0) solves them.&lt;/P&gt;
&lt;P&gt;The solutions given by inheritance, as I see them and in no particular order, are:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Easy code reuse 
&lt;LI&gt;Fix it in one place 
&lt;LI&gt;Removal of code redundancy (no more copy-and-paste code) 
&lt;LI&gt;Modeling real-world objects 
&lt;LI&gt;Breaking large problems into small, manageable pieces 
&lt;LI&gt;Pass a reference to the base class and use the same members, even though they are implemented totally differently (polymorphism) 
&lt;LI&gt;Not knowing or caring how the code was implemented or being able to talk to it directly (encapsulation)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;So does our current system in C# 3.0 (and VB 9.0) live up to these expectations? To some extent yes and to some extent no.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;When We Need Multiple-Inheritance&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;Let's say that I want to create a layer filled with business classes like Employee, EmployeeCollection, Vendor, VendorCollection, and a couple of hundred others. Some of these should be clonable and some should not. Some of these should be editable with rollback capabilities and some should not. Some of these should be bindable and some should not. Some of these should be bindable collections and some should not.&lt;/P&gt;
&lt;P&gt;For each of clonable, editable, bindable, and bindable collection we have the exact same code that we wish to apply everywhere. Plus we want to treat these objects the same in a clonable, editable, and bindable context regardless of what type of object they really are. Ideally, we could create 4 classes and inherit as many of which ever ones are needed for each situation.&lt;/P&gt;
&lt;P&gt;But that would require Multiple Inheritance, which we can't have. We can just create a single, common base class because each business class needs a different combination of these functionalities. We are back to re-inventing the wheel for each one of these and using error-prone "copy-and-paste inheritance". There goes more than half of our inheritance benefits. So what good is inheritance if we can't actually use it?&lt;/P&gt;
&lt;P&gt;The interesting thing here about these is that they are not examples of "is a kind of" relationships, as is commonly thought of with inheritance. After all, Employee isn’t a “kind of” Clonable or Editable or Bindable. All of these examples require "contracts for functionality", thus denoting interfaces. &lt;/P&gt;
&lt;P&gt;Indeed, we have the interfaces IClonable, IEditableObject, annd IBindingList. Some, myself included, have created the IBindable interface for extending IEditableObject. But even if we use Interfaces we only gain semi-polymorphic benefits and we are still doomed to copy-and-paste code.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;The Solution: Implementation Classes&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;The solution that I've been using is to create strong implementations of these interfaces and place them as private members in the class that I want to inherit them. The target class also implements the interface and exposes the various members of the private instances through it. For example:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; public class Clonable : ICloneable&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public object Clone()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... Use reflection to determine&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// &amp;nbsp;&amp;nbsp;&amp;nbsp; which class owns this instance&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... Use reflection and attributes&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; to produce the clone of the owner instance&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public class Employee : ICloneable&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Constructor that includes instanciating _Clonable&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private Clonable _Clonable;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public object Clone()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return _Clonable.Clone();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;While this is a simple example, the principal works with a whole host of interfaces. I've been using it very successfully to gain 99% of the benefits of MI without actually using MI.&lt;/P&gt;
&lt;P&gt;I call these types of strong implementations, such as the Clonable class in this example, Implementation Classes. It's not a full class because it has no value on its own and it is just one possible, yet common, implementation of an interface.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Calling the Constructor&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;With inheritance, the base class’ constructor is called as the first command in the inheriting class’ constructor. With an Employee class, the constructor would look something like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public Employee()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: base()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Constructor logic&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;In VB.NET the call to the base class’ constrictor is the first line of code inside of the constructor body instead of a part of the constructor definition. In any event, the base class constructor is the first thing called when creating a new instance of the inheriting class. &lt;/P&gt;
&lt;P&gt;With Implementation Classes, you must create the private instance that holds the functionality before you can use it. This should be done anywhere in the constructor body provided that nothing tries to use it before it is instantiated. &lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public Employee()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... some statements ... //&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_Cloneable = new Cloneable();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... some more statements ... //&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Parameterized constructors can be used as well, assuming the Implementation Class has one:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public Employee(bool CloneDeep)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... some statements ... //&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_Cloneable = new Cloneable(CloneDeep);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ... some more statements ... //&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;One could even delay the instantiation of the _Cloanble object until some point after the constructor has been called but this can be very dangerous because an outside object could call the Employee object’s Clone() method and generate a null reference exception.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Abstract (MustOverride) Members&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;Of course, Implementation classes can't really be like MI without the ability to create abstract members. The answer is in delegates.&lt;/P&gt;
&lt;P&gt;The implementation class should create a delegate that matches the desired signature of the member. It should then create a field to hold a reference to the delegate. Finally, the "abstract member" should just invoke the referenced delegate.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public delegate bool SomeAbstractMethodDelegate(string SomeParameter);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;private SomeAbstractMethodDelegate _SomeAbstractMethodInstance;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public bool SomeAbstractMethod(string SomeParameter)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return _SomeAbstractMethodInstance.Invoke(SomeParameter);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Since this is an abstract method and should be "overridden" before any functionality takes place, the best place to pass the delegate would be in the constructor. &lt;/P&gt;
&lt;P&gt;If you were looking for a dynamically-overridable method that could change at any moment you could just wrap the _SomeAbstractMethodInstance field into a read/write property and throw an exception if someone tried to set it to null. This does, however, give the programmer enough rope to hang themselves and every member of their IT department.&lt;/P&gt;
&lt;P&gt;Virtual (Overridable) members can be handled in a similar way but would require some extra plumbing to be able to call the original vs. the overridden version, as can be done with true inheritance.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;The Benefit&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;What benefits do we really gain by using the concept of Implementation Classes? Now, instead of copying and pasting the full implementation of an interface over and over and over again, you only have to:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Build the implementation class once based on an interface 
&lt;LI&gt;Create a private member instance of the Implementation class 
&lt;LI&gt;Add ": [InterfaceName]" to the end of your "inheriting" class 
&lt;LI&gt;Paste a block of code that simply implements the interface members by calling the private implementation object's member of the same name&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;I have a very large project with classes that each implements some of a dozen different interfaces in the exact same way. Since each class implements a different number and variety of these interfaces, creating a base class for all of them is not an option. Implementation Classes have largely given me back the benefits of Multiple Inheritance and they have given me back my sanity. Best of all, they don’t really violate any rules of inheritance.&lt;/P&gt;
&lt;P&gt;There still is some copy-and-paste code, which causes me grief, but it is greatly reduced and it is much easier to debug the entire solution.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Where does this leave us?&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;At the end of the day, this still doesn't give us Multiple Inheritance and it still doesn't eliminate all of the redundant copy-and-paste inheritance that must be done with interfaces. But it does give the benefits of easy code reuse, fix it in one place, far less copy-and-paste code, elimination of copy-and-paste of critical code, and it allows us to further break the problem into smaller, manageable pieces.&lt;/P&gt;
&lt;P&gt;It also underscores the fact that there are two types of inheritance: "Is a kind of" and "constrict for functionality". MI often boils down to wanting multiple contracts for functionality with the actual functionality in tact. Implementation Classes deliver just that.&lt;/P&gt;
&lt;P&gt;Happy Coding&lt;BR&gt;- Shaun&lt;BR&gt;&lt;/P&gt;&lt;FONT face="Courier New"&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=141899" width="1" height="1"&gt;</description></item><item><title>Microsoft Releases Visual A++ (Object Oriented Assembler)</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2006/04/01/135017.aspx</link><pubDate>Sat, 01 Apr 2006 05:00:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:135017</guid><dc:creator>shayward</dc:creator><slash:comments>0</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/135017.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=135017</wfw:commentRss><description>&lt;P&gt;&lt;FONT&gt;Today, the Redmond giant revealed the fruits of its hush-hush labours. Visual A++, or Object Oriented Assembler, is available as a free language add-on for Visual Studio 2005 and targets the .NET Framework. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;It supports the full 80x86 set of opcodes, up to an including the new opcodes introduced in Intel's Prescott chip. A subsequent version, due out mid-summer, will include opcode support for some specialized AMD opcodes.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;There are many obvious benefits of having things like a static register class, structured JUMP blocks, and writing device drivers in a class-based assembly language. Windows Vista will support device drivers written entirely in managed C# or VB code so Visual A++ is no doubt part of this strategy.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;The version of Visual A++ that ships with Orcas is expected to add the ability to define custom processors and mix the unique opcodes from various processors through DLLs in much the same way that VB and C# work together. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;This allows assembler programmers from any background to instantly write not just libraries and device drivers but also Windows Forms and Web Forms applications. The seasoned programmer can immediately see the benefit of switching from VB to Motorola 6800 Assembler for ASP.NET 2.0 development.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;The most dynamite feature, however, is the full compatibility with classic MASM and TASM, meaning that any old piece of 80x86 code will compile and target the .NET Framework. Thexder, Deskmate, and Bedford Accounting are among the old DOS applications due to be re-released as full Windows applications in managed code early in 2007. No more than a mere recompile is required.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;In fact, any EXE, DLL, or set of executable components can be decompiled into Assembly language, used in Visual Studio, and compiled to IL. Combine this with the Mono project and we may just see Microsoft Word or any Windows software suddenly become available for Linux.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Just think of what this will do to open up the markets for your software projects. Rumor has it that there is one team currently working on a fully-managed Windows XP port and a version of .NET that will run on Motorola and PowerPC processors. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;This means that OSX may not be the only choice for your pre-Intel G4. It's about time that someone broke Apple's unfair OS monopoly on its own hardware.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Also exciting is a rumor that Microsoft developers are presently hard at work on A#, which is pure CIL integrated into Visual Studio. Developers may soon be able to use a cil{} block in C# to drop to Common Intermediate Language, just like C developers can drop to Assembler.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;I would leave you to ponder the future of computing if it were not for my closing:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Happy Coding and Happy April Fools Day&lt;BR&gt;- Shaun&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=135017" width="1" height="1"&gt;</description></item><item><title>When Object Oriented Doesn't Wax Relational - Part 3</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2006/02/02/135011.aspx</link><pubDate>Thu, 02 Feb 2006 20:10:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:135011</guid><dc:creator>shayward</dc:creator><slash:comments>773</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/135011.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=135011</wfw:commentRss><description>&lt;P&gt;&lt;FONT&gt;In a previous post entitled &lt;/FONT&gt;&lt;a href="http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/12/01/134096.aspx"&gt;&lt;FONT&gt;MVP: Object Oriented is Academic, Religion&lt;/FONT&gt;&lt;/A&gt;&lt;FONT&gt; I discussed a classic example of persisting OO classes to RDBMS tables. I have now given two possible solutions in the posts &lt;/FONT&gt;&lt;a href="http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/12/16/134353.aspx"&gt;&lt;FONT&gt;When Objects Don't Wax Relational - Part 1&lt;/FONT&gt;&lt;/A&gt;&lt;FONT&gt; and &lt;/FONT&gt;&lt;a href="http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2006/01/02/134536.aspx"&gt;&lt;FONT&gt;When Objects Don't Wax Relational - Part 2&lt;/FONT&gt;&lt;/A&gt;&lt;FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Now onto Part 3, which outlines my preferred solution.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;&lt;STRONG&gt;&lt;U&gt;Solution 3 - One to One of Different Types&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;Really, what we want to say is that each ContactInformation record relates to one other record but that record is one of many different possible types. This kind of relationship doesn't exist natively in SQL Server but can be produced manually.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;As with the previous solution, there is only one instance of the ContactInformation, Address, Telephone, and Email tables. Address, Telephone, and Email records are each owned by a single ContactInformation record. Nothing radical so far. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;The difference is the way in which each ContactInformation record relates to its parent record. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;In this solution, ContactInformation contains two columns: ParentID and ParentType. ParentID is like a foreign key field but can contain a primary key value from a Vendor, Employee, or Customer record. The ParentType field is a text field that contains the possible strings "Vendor", "Employee", or "Customer", thus telling us the type of parent record.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Compared with the&amp;nbsp;&lt;/FONT&gt;&lt;a href="http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2006/01/02/134536.aspx"&gt;&lt;FONT&gt;previous&lt;/FONT&gt;&lt;/A&gt;&lt;FONT&gt; solution, the INNER JOIN statement is much clearer in terms of how the tables relate:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT * FROM ContactInformation&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;INNER JOIN Vendor ON ContactInformation.ParentID = Vendor.ID&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AND ContactInformation.ParentType='Vendor'&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE Vendor.ID=@IDValue&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Likewise, we can go the other way:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT * FROM Vendor&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;INNER JOIN Vendor ON ContactInformation.ParentID = Vendor.ID&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AND ContactInformation.ParentType='Vendor'&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE ContactInformation.ID=@IDValue&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;These SQL statements are very clear about their intentions. The only difference between these relationships and a standard one-to-one relationship is the addition of "AND ContactInformation.ParentType='Vendor'", which isn't really a major inconvenience. Nevertheless, this solution also carries a few issues:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;1. It would be possible to orphan ContactInformation records by putting nonsense data in the ParentID and ParentType fields&lt;BR&gt;2. Forgetting to add "AND ContactInformation.ParentType='TableName'" may yield undesired results&lt;BR&gt;3. This is a non-standard, albeit straight-forward, approach and would have to be well documented for the benefit of those maintaining the code&lt;BR&gt;4. Performance would suffer due to the doubling in the number of comparisons in a JOIN and making one of the comparisons text-based &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;If you absolutely must wax OO in a relational database, something like this may work for you. The use of triggers can alleviate the lack of referential integrity; 7+ years ago all relationships were done with triggers. Performance becomes less and less of an issue every year with RAM, CPU-speeds, and Hard Drive speeds all increasing. Plus you could always use constants mapped to numeric values to represent the parent type.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;This solution certainly wouldn't be the answer for a small-scale project where redundant work doesn't have the same impact. This solution could really shine in a large-scale system where programmers create code-based "Lego blocks" and fit them together in different ways, particularly in ERP systems.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Maybe I'm a little crazy, but given the current features in SQL Server and what I've seen so far with O/R Mappers, this really is my solution of choice. At the very least, it's some good food for thought.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Happy Coding&lt;BR&gt;- Shaun&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=135011" width="1" height="1"&gt;</description></item><item><title>Toronto Code Camp 2006 an Overwhelming Success</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2006/01/18/134795.aspx</link><pubDate>Wed, 18 Jan 2006 19:14:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:134795</guid><dc:creator>shayward</dc:creator><slash:comments>3</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/134795.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=134795</wfw:commentRss><description>&lt;P&gt;The 2006 &lt;A href="http://www.torontocodecamp.com"&gt;Toronto Code Camp&lt;/A&gt; was the first .NET code camp in Toronto and the largest .NET code camp in Canadian history. There were over 200 geeks present, all focused on programming for the .NET Framework. What a great experience. As it turns out, I'm one of the few that actually look like geeks. Most seem to be normal and a few are even metro-sexual.&lt;/P&gt;
&lt;P&gt;There were 20 available 1 hour 15 minute talks spread out over 4 streams and attendees weren't locked into a particular stream. It was a buffet-style feast of current and future technical knowledge including Threading, LINQ, Visual Studio Team System, AJAX, Microsoft Enterprise Library, Mobile Development, .NET Futures, and Code Access Security.&lt;/P&gt;
&lt;P&gt;One aspect of the code camp was the target of having 10 neophyte speakers. I had the privilege of being one of them and spoke on creating applications with a Professional Look-and-Feel using &lt;A href="http://www.infragistics.com"&gt;Infragistics&lt;/A&gt; &lt;A href="http://www.infragistics.com/products/NetAdvantage/default.aspx"&gt;NetAdvantage&lt;/A&gt;. It was the first time that I have ever spoken to a technical audience (aside from coworkers), given a Power Point presentation, and lectured for over an hour.&lt;/P&gt;
&lt;P&gt;It's spooky and humbling to realize that I have actually accumulated enough experience to have something worth listening to. It is largely thanks to wealth of guidance given directly and indirectly by peers that I shall never be able to equal in knowledge and understanding.&lt;/P&gt;
&lt;P&gt;It's also nice to learn that I rather enjoy public speaking. Of course, having a good and responsive crowd made the whole experience quite pleasant. I'm looking forward to speaking to the &lt;A href="http://gtaeast.torontoug.net"&gt;East of Toronto .NET User Group&lt;/A&gt;&amp;nbsp;in February.&lt;/P&gt;
&lt;P&gt;Winning the grand prize of an &lt;A href="http://shopping.msn.com/reviews/shp/?itemId=238132877"&gt;MSDN Premium Subscription with Team Suite&lt;/A&gt; was the thick, gooey, chocolaty icing on the cake.&lt;/P&gt;
&lt;P&gt;The day will certainly be one of my best and most memorable ever. It may not beat out my absolute most memorable days, including my wedding day, the birth days of each of my children, or the day I accepted Jesus, but it sure rates up there as a solid second.&lt;/P&gt;
&lt;P&gt;Here's to the 2007 Toronto Code Camp. I hope to see you there.&lt;/P&gt;
&lt;P&gt;Happy Coding &lt;BR&gt;- Shaun&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=134795" width="1" height="1"&gt;</description></item><item><title>When Object Oriented Doesn't Wax Relational - Part 2</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2006/01/02/134536.aspx</link><pubDate>Mon, 02 Jan 2006 21:15:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:134536</guid><dc:creator>shayward</dc:creator><slash:comments>4</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/134536.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=134536</wfw:commentRss><description>&lt;P&gt;&lt;FONT&gt;In a previous post entitled&amp;nbsp;&lt;a href="http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/12/01/134096.aspx"&gt;MVP: Object Oriented is Academic, Religion&lt;/A&gt; I discussed a classic example of persisting OO classes to RDBMS tables. I gave one possible solution in the post&amp;nbsp;&lt;a href="http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/12/16/134353.aspx"&gt;When Object Oriented Doesn't Wax Relational - Part 1&lt;/A&gt;. In part two, I will examine another possible solution. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Hats off to Chris Falter for beating me to it. He added a comment at the end of the Part 1 post, suggesting the very solution that I planned to cover here in Part 2. We each have a slightly different angle on it but are talking about the same thing.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&lt;STRONG&gt;&lt;U&gt;Solution 2 - Reversing the Relationships&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT&gt;When performing an inner join, SQL doesn't care which field is the primary key and which is the foreign key. In fact, it doesn't even care* if either field is a primary key or foreign key.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;I have seen solutions that use this to their advantage. I've even authored one. When applied to our example, there would be single ContactInformation, Address, Telephone, and Email tables. Address, Telephone, and Email all have a foreign key field called ContactInformationID that relates back to its parent ContactInformation record.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;In traditional relational database design, the ContactInformation table would a foreign key field that relates to its parent. Because of our unique scenario, each ContactInformation record could be "owned" by a record from different tables - in this case, Employee, Customer, or Vendor. Thus, ContactInformation cannot have a single foreign key field that references a parent record.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Instead, the parent tables each have a ContactInformationID field that is a foreign key and relates to the ContactInformation table's primary key. INNER JOIN statements become fairly simple:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;STRONG&gt;SELECT * FROM ContactInformation&lt;BR&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;STRONG&gt;INNER JOIN Vendor ON Vendor.ContactInformationID = ContactInformation.ID&lt;BR&gt;WHERE Vendor.ID=@IDValue&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;This certainly allows us to map one table to one class and it makes writing persistence code much easier. We are at least getting the 1-to-1-of-different-types correlations that we desire with far less work. This solution does, however, have some short-comings:&lt;/FONT&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;FONT&gt;It would be possible to have a Vendor, Employee, and Customer all reference the same ContactInformation record, thus defeating referential integrity&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT&gt;The ContactInformation would have to be persisted first, which isn't really a big problem&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT&gt;The reality of the database structure is opposite the intention of the solution, which is confusing&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT&gt;The intention of a SQL Statement is easily misunderstood&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT&gt;This is a very non-standard approach and would have to be very well documented for those maintaining the code&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;FONT&gt;It's not to say that a solution such as this couldn't work, but, like growing a Bonsai Tree, the conditions would have to be perfect. It would be best applied to a large-scale system where database performance is of the essence, all code is object oriented, the code is all maintained in-house, all developers are well versed in the art of OOP, all developers fully understand why relationship-reversal is being used, and the scenario warrants this type of relationship. This may be a pretty tall order.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Some Nay-Sayers may view this solution as invalid due to bad database design. It's not to say that they would be wrong in this view, but when convergence point between two very different theories, methodologies, or technologies is often quite messy. As architects, we have to choose whether we want that mess in the database (as with this scenario) or in the code. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Typically, the messy part ends up in the code. As a lover of OOP and lukewarm to relational databases, I somewhat begrudge this. But I appreciate why this is the case. Often, several different solutions from several different vendors will be written against the same database. The cleaner the database, the better all around.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;So would I use this solution? It sure wouldn't be my first choice but if the conditions were fertile and nothing else would work then I would at least consider trying to grow a good crop of reversed-relationships just to keep my farming simple.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Happy Coding&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;- Shaun&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;* There will, of course, be mild-to-moderate performance issues if the fields utilized in the JOIN are not indexed&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=134536" width="1" height="1"&gt;</description></item><item><title>When Object Oriented Doesn't Wax Relational - Part 1</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/12/16/134353.aspx</link><pubDate>Fri, 16 Dec 2005 13:27:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:134353</guid><dc:creator>shayward</dc:creator><slash:comments>523</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/134353.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=134353</wfw:commentRss><description>&lt;P&gt;&lt;FONT&gt;In a previous post entitled &lt;/FONT&gt;&lt;a href="http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/12/01/134096.aspx"&gt;&lt;FONT&gt;MVP: Object Oriented is Academic, Religion&lt;/FONT&gt;&lt;/A&gt;&lt;FONT&gt;&amp;nbsp;I discussed a classic example of persisting OO classes to RDBMS tables. Here’s a recap:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;We have 4 classes that hold contact information. They are: ContactInformation, Address, Telephone, and Email. ContactInformation can hold zero-through-infinity each of Address, Telephone, and Email.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Normally, we would create 4 tables that correspond to the 4 classes. ContactInformation would have a primary key and Address, Telephone, and Email would each have a foreign key called ContactInformationID.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;The problem is that in our class design, we have the classes Vendor, Employee, and Customer. Each of these has a ContactInformation member of the type ContactInformation. This simplifies our code because a single change or fix to any of the 4 contact-related classes is immediately reflected in the Vendor, Employee, and Customer classes.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;The big question is this: how do we design the data storage for a relational database management system and how do we write our persistence code?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;There are three possible solutions that I can see and I would like to cover the first one today.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;&lt;FONT&gt;&lt;STRONG&gt;&lt;U&gt;Solution 1 - Separate Tables&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;It seems that the most "referentially integral" solution would be to create separate tables to house the contact information for each of Vendor, Customer, and Employee. Thus, we have the following tables:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT&gt;VendorContactInformation &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;VendorAddress &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;VendorTelephone &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;VendorEmail &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;CustomerContactInformation &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;CustomerAddress &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;CustomerTelephone &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;CustomerEmail &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;EmployeeContactInformation &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;EmployeeAddress &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;EmployeeTelephone &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;EmployeeEmail.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT&gt;While it does mean that the database maintains its own integrity (a good thing indeed), it certainly has some issues:&lt;/FONT&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;FONT&gt;When we make a change to the structure of any of the ContactInformation and related classes, we must make the change 3 times in the database and possibly in several redundant persistor objects in our code &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;We must create a fairly heavy single persistor in our code or else Vendor, Customer, and Employee must each have their own ContactInformation persistor &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;To do a search for a piece of contact information (e.g. a telephone number) regardless of what type of entity to which it belongs, we must perform a union in a view or subquery &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT&gt;When adding additional entities (e.g. ShippingCompany, Manufacturer, Agency) that each include the ContactInformation class, we must reproduce everything over again and update several views&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;FONT&gt;A portion of the inconvenience could be fixed with stored procedures by creating, say, sp_GetAddresses that takes the Vendor, Employee, or Customer ID and a string denoting whether we are after the addresses for a Vendor, Employee, or Customer. At least the use of stored procedures can make persistence and retrieval more generic.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;I have no doubt that this is a common solution but it certainly is cumbersome. The OO code makes standardization and maintainability so easy but the database's limitations seem to undo this advantage quite quickly.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;This classic solution just doesn’t seem to have the forward-thinking for where we are heading in the future. It is, however, safe. Please feel free to post your own ideas, no matter how conservative or how crazy. I've got a few more ideas coming up that are sure to get me a one-way-ticket to the looney bin.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Happy Coding&lt;BR&gt;- Shaun&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=134353" width="1" height="1"&gt;</description></item><item><title>MVP: Object Oriented is Academic, Religion</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/12/01/134096.aspx</link><pubDate>Thu, 01 Dec 2005 14:36:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:134096</guid><dc:creator>shayward</dc:creator><slash:comments>1</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/134096.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=134096</wfw:commentRss><description>&lt;P&gt;&lt;FONT&gt;Tuesday, November 8, 2005 was a day of wonders with the Toronto VS2005 Launch event. This was the first time that I have attended such an event. I burst into laughter when I saw the "rock concert" style complete with giant sparkle-filled balloons for the audience to bat around while AC/DC blasted over the loud speakers completely with accompanying multi-screen video.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;There is something seemingly absurd about geeks trying to pretend to be cool. Granted, as I look all around me at various nerd events I notice that many of my programmer contemporaries are turning into metrosexuals. As for me, I will continue to wear electrical diagram print suspenders and glasses held together with scotch tape.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;All in all, I was very impressed with the day's events. Microsoft is really good to their developers.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;One great resource that they had available was an array of MVP's that were ready, willing, and able to answer all of your development questions. Adorned in matching tight-knit cotton shirts with the word "Expert" written down one sleeve, I was sure they could satisfy even my deepest burning curiosities. This time, I decided to ask about the age-old question of persisting class structures into a relational database.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;FONT&gt;The Example&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Suppose we have a ContactInformation class. This class contains an Address collection, a Telephone collection, and an Email collection. Thus, each ContactInformation class can have 0-through-many addresses, telephone numbers, and email addresses. Each Address has an AddressType (such as Shipping, Billing, Mailing, etc.), each Telephone has a TelephoneType, and each Email has an EmailType.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Persisting this to a relational database makes sense. You create an Address table, a Telephone table, and an Email table. Plus you can either use enumerated values or create tables for AddressType, TelephoneType, and EmailType. The programmer may wish to create a ContactInformation class in case there are some extra details contained therein.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;The problem comes when we wish to have a Vendor class, Customer class, and Employee class - each having ContactInformation as a member. Obviously, we must create Vendor, Customer, and Employee tables but how do we related them to the ContactInformation table? &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;FONT&gt;The Microsoft Expert Answer&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;For an expert (and leader of a SQL Server user group), I certainly wasn't the least bit impressed. I started to ask my question about mapping objected oriented classes into SQL Server when he interrupted and gave me a 5-minute lecture on why "object oriented" is a religion.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Instead of letting me ask my question (which wasn't on the merits of OOP) and giving me an answer (I was hoping to learn more about O/R Mappers), he decided to go on a tirade about performance problems and why he doesn't use object oriented programming for anything. He said that the only benefit to object oriented programming is code maintainability and other than that, it is useless. There was something in there about it being solely an academic pursuit that unfortunately some people have tried to apply to the real world.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Too bad Microsoft disagrees with that assessment. VSTS includes a pretty sweet class designer, System.Drawing is a set of class wrappers over GDI, and WinFX takes away ugly API's and replaces them with class wrappers. Everything in the Microsoft world is heading OO – thank goodness.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Now, I've heard the Multiple Inheritance debate referred to as a religion but I thought that OOP in general was long past being an obscure prophesy of&amp;nbsp;&lt;/FONT&gt;&lt;FONT&gt;&lt;A href="http://www.research.att.com/~bs/homepage.html"&gt;Bjarne Stroustrup&lt;/A&gt; and was now accepted as the de facto way to get most things done.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;I guess when it comes to the word "Expert", the old adage holds true: X is the unknown quality and a spurt is the force behind a drip.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Happy Coding&lt;BR&gt;- Shaun&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=134096" width="1" height="1"&gt;</description></item><item><title>Extension Methods: Still Not Multiple Inheritance</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/11/01/133513.aspx</link><pubDate>Tue, 01 Nov 2005 14:40:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:133513</guid><dc:creator>shayward</dc:creator><slash:comments>1</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/133513.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=133513</wfw:commentRss><description>&lt;P&gt;&lt;FONT&gt;Extension Methods can be used as a piece of pseudo-multiple-inheritance for methods, but they really have a different purpose than Inheritance and Multiple Inheritance. In some cases, Extension Methods can be used as a substitute for Multiple Inheritance. That said, if C# 5.0 (presently fictitious) has both Extension Methods and Multiple Inheritance, both will continue to be used as solutions for different types of problems.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Inheritance gives us the 'is a kind of' relationship between classes. It also causes us to inherently gain functionality (methods &amp;amp; events), attributes (properties &amp;amp; fields), and state (values in properties &amp;amp; fields). It also allows us to cast back up the class hierarchy, tie together many related members in a tight manner, and override functionality thus giving us polymorphism. When desiring to make changes that impact all classes further down the hierarchy, we must have access and/or liberty to make changes to the base class - a luxury that is not always afforded us.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Extension Methods do not give us any kind of relationship ('is a kind of', 'contract for functionality', or otherwise). They do not give us attributes nor do they give us state. They do not give us casting, they do not tie together many related members, nor do they allow overriding &amp;amp; polymorphism. Extension Methods, however, do not require any modifications to the base classes and thus we can extend functionality of an existing class without restriction.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;What Extension Methods do is give us the ability to add a simple, stand alone method to existing classes with no intrusion whatsoever. I've heard them described (quite accurately) as "syntactic sugar" implemented in the compiler. It merely changes:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT face="Courier New"&gt;MyStaticIListHelperClass.Merge(IList1, IList2);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;into:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT face="Courier New"&gt;IList1.Merge(IList2);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;My understanding of Extension Methods is that the latter statement in this example would actually compiles into the former.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;While Extension Methods can serve a small part of the same function as Multiple Inheritance, they certainly don't eliminate the need for Multiple Inheritance and they are really intended for a different purpose. Nevertheless, they are a most welcome addition and will be of great use in many of our solutions. All we have to do now is wait for Visual Studio Next.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Happy Coding&lt;BR&gt;- Shaun&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=133513" width="1" height="1"&gt;</description></item><item><title>Multiple Inheritance Solutions: Extension Methods</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/10/31/133497.aspx</link><pubDate>Mon, 31 Oct 2005 14:09:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:133497</guid><dc:creator>shayward</dc:creator><slash:comments>0</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/133497.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=133497</wfw:commentRss><description>&lt;P&gt;&lt;FONT&gt;C# 3.0 will see the light of day sometime in 2007-2008 with an exciting new feature: Extension Methods. I was browsing a document authored by Anders Hejlsberg with all of the upcoming LINQ-related stuff when I stumbled on them. "My goodness! We've got Multiple Inheritance!" was my first reaction. Indeed, Extension Methods give us Multiple Inheritance... kind of.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;It is an important feature that gives us a small piece of Multiple Inheritance functionality, even if it’s not the Redmond-sent fulfillment to Multiple Inheritance prophesy that I first thought. Essentially, an Extension Method let's you create a static (Shared in VB) method that will "look like" it is a method in one or more classes of a given type.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Let's suppose that you wish that IList, TextBox, or a 3rd-part ComboBox had certain methods to accomplish specific tasks. You could always make your own derived classes with the methods that you want. This is a good technique in some cases - especially when you need to add many methods, properties, and events as well as override some members. For simply adding a disjointed method or two, however, there are some drawbacks:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;1: if you want all of your objects to have the new method then you must replace every declaration or modify the base class&lt;BR&gt;2: if you expand an interface you will have to change all of the classes that use it &lt;BR&gt;3: you will not be able to make changes to objects that are part of a framework, rendering your new method useless for them&lt;BR&gt;4: you cannot add methods to the System.Object class, even though you may want to add a method to every class in your project&lt;BR&gt;5: it requires an awful lot of work for the simple goal of adding a method or two&lt;BR&gt;6: Sometimes you want to modify classes that form a composite but cannot do so without ugly (and error-prone) member hiding&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;When adding a simple method that is stateless and stand-alone, often programmers will create a static class with a static method. One might create a static method to merge together two IList objects by adding all of the second IList's items to the first.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT face="Courier New"&gt;public static void Merge(IList Destination, IList Source) { ... }&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;One can even go as far as to make a version for the generic IList.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT face="Courier New"&gt;public static void Merge(IList Destination, IList Source) { ... }&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;This is a very good way of "adding stand-alone functionality" to an existing class without actually making changes to it. I find myself doing this quite often with grids when I have a common way of setting up columns based on attributes in the data source.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Assuming that the aforementioned static Merge method belongs to a static class called IListHelper, calling the method would be done as follows:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT face="Courier New"&gt;IListHelper.Merge(FirstIListObject, SecondIListObject);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;There is no shame in this syntax, but it may not be as clear as one would like. Perhaps you wish that IList itself had the merge method and that it worked exactly the same as your code in the static method. The net result should be the same but the syntax should look like:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT face="Courier New"&gt;FirstIListObject.Merge(SecondIListObject);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;If you like this syntax better, congratulations! This is Extension Methods.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;While calling the static class is not really confusing or unclear, calling the Merge method as if it is a member of IList is even clearer still. It's kind of like the difference between photocopier paper and the really bright laser paper - photocopier paper looks white until you hold it next to the good stuff.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;All it takes it one small change to our static method declaration:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT face="Courier New"&gt;public static void Merge(this IList Destination, IList Source) { ... }&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;The "this" keyword added before the parameter list tells the compiler that Merge is an Extension Method. The first parameter in the list tells the compiler (and IntelliSense) which type of object can use the static method as an Extension Method. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Casting backwards does apply so any class that implements IList can also use the extension method. This is helpful in a variety of situations - especially if there is a method that we want to apply to all classes. One example might be to output the return of ToString to the console.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static void WriteToConsole(this object o) { ... }&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SomeEmployeeObject.WriteToControle();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;There are no doubt thousands of ways to use this new feature. While it doesn't remove the need for Multiple Inheritance (or, at least, not much of it) it does give us another tool that is a kind of basic Multiple Inheritance. C# 3.0 is just a baby and I'm personally hoping that it will include Extension Properties and Extension Fields as well.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Happy Coding&lt;BR&gt;- Shaun&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=133497" width="1" height="1"&gt;</description></item><item><title>Multiple Inheritance Solutions: We Must Use Interfaces</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/10/28/133462.aspx</link><pubDate>Fri, 28 Oct 2005 16:06:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:133462</guid><dc:creator>shayward</dc:creator><slash:comments>4</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/133462.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=133462</wfw:commentRss><description>&lt;P&gt;&lt;FONT&gt;Wesner Moise added some very noteworthy&amp;nbsp;&lt;/FONT&gt;&lt;a href="http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/10/19/133305.aspx#133311"&gt;&lt;FONT&gt;comments&lt;/FONT&gt;&lt;/A&gt;&lt;FONT&gt; to my &lt;/FONT&gt;&lt;a href="http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/10/19/133305.aspx"&gt;&lt;FONT&gt;Baby Steps Towards Multiple Inheritance in .NET&lt;/FONT&gt;&lt;/A&gt;&lt;FONT&gt; post. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Some objections to MI surround multiple vtables and keeping them lined up. It is the most intelligent argument against true Multiple Inheritance by far. Granted, it is not an argument that Multiple Inheritance is bad but rather it is difficult for the CLR to implement. People that understand this far better than I do include &lt;/FONT&gt;&lt;A href="http://dotnetjunkies.com/WebLog/unknownreference/archive/2003/09/04/1401.aspx"&gt;&lt;FONT&gt;Chris Brumme&lt;/FONT&gt;&lt;/A&gt;&lt;FONT&gt;&amp;nbsp;and &lt;/FONT&gt;&lt;A href="http://wesnerm.blogs.com/net_undocumented/2004/01/multiple_inheri.html"&gt;&lt;FONT&gt;Wesner Moise&lt;/FONT&gt;&lt;/A&gt;&lt;FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;The bottom line is this: &lt;U&gt;&lt;STRONG&gt;implementing true Multiple Inheritance is going to be a serious pain in the backside for the CLR team.&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Yet we don't seem to have any trouble whatsoever with Multiple Interface inheritance. Therefore, we need to use interfaces as a starting point for any Multiple Inheritance endeavors. This won't lead to true MI but we may be able to get almost all of the functionality of true MI without true MI and the drawbacks that accompany it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Furthermore, any model that is based on interfaces would be portable to Java, Delphi, and other languages. I am presently aware of a few different methods for Multiple Inheritance using Interfaces. These include Default Interface Implementation and Implementation Classes. If you are aware of others, let me know.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;I will cover both of the solutions that I know in further detail in upcoming posts. For now, I want to lay it all down and be perfectly clear: true Multiple Inheritance is not likely to exist in .NET for many, many years - if ever. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;However, an interface-based solution would be extremely easy for the .NET teams to implement with very minor changes. That is what I believe we should be encouraging for the Hawaii (or even Orcas, if we shout loud enough) timeframe.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Happy Coding&lt;BR&gt;- Shaun&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=133462" width="1" height="1"&gt;</description></item><item><title>When is Multiple Inheritance a Good Thing?</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/10/27/133441.aspx</link><pubDate>Thu, 27 Oct 2005 12:57:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:133441</guid><dc:creator>shayward</dc:creator><slash:comments>2</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/133441.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=133441</wfw:commentRss><description>&lt;P&gt;&lt;FONT&gt;Multiple Inheritance isn't right for every situation. Many solutions never need Multiple Inheritance. Many solutions that could use Multiple Inheritance shouldn't use it because it is the wrong place. Yet one project that I'm working on right now would use MI in about 70% of the classes if it were now available and the code would be simpler, more robust, and more reliable.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;There are many nay-sayers that will argue, "How can you have a class with multiple 'is a kind of' relationships?" They would be right, except that we can have multiple interfaces on a single class. Of course, nay-sayers will further argue, "That's different. An interface defines a 'contract for functionality' rather than an 'is a kind of' relationship."&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;This is where it gets a little gray. If I have a class called EmployeeCollection that implements IList, doesn't EmployeeCollection become 'a kind of' IList? Indeed, it does! And what if I want the same IList implementation for both EmployeeCollection and VendorCollection?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;So why not just inherit a regular class like ArrayList or the List&amp;lt;&amp;gt; class? That way, you get IList&amp;lt;&amp;gt; and the 100% identical implementation in both EmployeeCollection and VendorCollection. That's a great idea and is one of the main reasons for Inheritance. You code it once, inherit it many times, and fix bugs only once. This also eliminates the numerous "copy and paste" errors.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Now let’s suppose that we have come up with a sophisticated implementation of IComparable that uses reflection, can look through lists and use the IComparable interface on list items, etc. We roll this functionality into a class called Comparable&amp;lt;&amp;gt; and can inherit it if we want to use it in a class. Because .NET only supports Single Inheritance, we cannot have EmployeeCollection inherit both List&amp;lt;&amp;gt; and Comparable&amp;lt;&amp;gt;. We are back into the messy, error-prone copy and paste method of Interface Implementation.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;The Single Inheritance answer may seem clear: create a class that inherits List&amp;lt;&amp;gt; and has all of the Comparable&amp;lt;&amp;gt; functionality. Call it ComparableList&amp;lt;&amp;gt;. The problem is that we want to inherit from Comparable&amp;lt;&amp;gt; on the Employee and Vendor classes and these classes don't need the List&amp;lt;&amp;gt; portion because they are not collections.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;In effect, sometimes we want to inherit List&amp;lt;&amp;gt;, sometimes we want to inherit Comparable&amp;lt;&amp;gt;, and sometimes we want to inherit both. This is further complicated by the fact that we have also created a standard implementation of IClonable called Clonable as well as our own custom interface called IPersistable with a general Persistable class that implements it. We may even want to do the same for IEditableObject.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;We may have identical implementations of a dozen interfaces that we wish to join in various combinations with 1000 or more classes within our solution. Suppose that 1000 classes want to inherit the Clonable class but cannot because they already inherit the Comparable&amp;lt;&amp;gt; class. Therefore, we have to copy and paste the Clonable class code into 1000 classes. When we make a change to the standard Clonable code, we have to change 1000 classes. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Not only does this waste a huge amount of time but it also greatly increases the chances of introducing new bugs. If this scenario seems unrealistic, rest assured that it is not – especially when working with 500+ table databases.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;The one interesting thing about this example is that all of the desired Multiple Inheritance really seems to hover around common Interface Implementation. Even though Clonable&amp;lt;&amp;gt; is a class, inheriting it really says that you want the contract for functionality plus the standard functionality itself. It does not imply the desire for an 'is a kind of' relationship.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;My personal opinion is that multiple inheritance is good when you really want to have multiple contracts for functionality with identical implementation on several (perhaps 1000s of) different classes. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;We still only need a single 'is a kind of' relationship for each class. We inherit other classes to provide both the Contract for Functionality as well as to implement that contract in a common way.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;This isn't indicative of the theory for true Multiple Inheritance but in my own experience it certainly is the most practical application for it. While it wouldn't satisfy all developers, I think that most of us would be more than happy with some form of Default Interface Implementation. In the truest sense of what DII would represent, I think that most of us would end up using that for most of our classes rather than inheriting from things such as List&amp;lt;&amp;gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;I've submitted an early vision of what I call Implementation Classes through the MSDN Product Feedback Center. Check it out at &lt;/FONT&gt;&lt;A href="http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?FeedbackId=6b4749b0-42be-4e21-90fb-b2e57c9d1adf"&gt;&lt;FONT&gt;http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?FeedbackId=6b4749b0-42be-4e21-90fb-b2e57c9d1adf&lt;/FONT&gt;&lt;/A&gt;&lt;FONT&gt; and see what you think. The idea is still early and I am continuing to work on it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Happy Coding&lt;BR&gt;- Shaun&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=133441" width="1" height="1"&gt;</description></item><item><title>A Geek's Perspective on the journey</title><link>http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/10/25/133419.aspx</link><pubDate>Tue, 25 Oct 2005 19:58:00 GMT</pubDate><guid isPermaLink="false">58df7014-fd75-437c-9641-150997716d1c:133419</guid><dc:creator>shayward</dc:creator><slash:comments>0</slash:comments><comments>http://www.dotnetjunkies.com/WebLog/dotnetmi/comments/133419.aspx</comments><wfw:commentRss>http://www.dotnetjunkies.com/WebLog/dotnetmi/commentrss.aspx?PostID=133419</wfw:commentRss><description>&lt;P&gt;&lt;FONT&gt;We're all geeks. If you're not a geek then you're really reading the wrong blog. I thought that for something light-hearted I would give&amp;nbsp;this geek's perspective on the journey towards what Dogbert referred to as "Nerdvana".&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;My name is Shaun Hayward and I grew up in the small town of Beaverton, Ontario, Canada, attending Brock High School and graduating far below honours*. We didn't do the "most likely to..." awards, but if we did I would have been voted "Most likely to achieve an Olympic gold medal in heavy-weight vagrancy before the age of 25."&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;While I never took a computer class in high school, I quickly discovered that handing the administrator his password on a piece of paper can be a great source of amusement. While I never had the testicular fortitude to do that myself, I lived vicariously through my braver contemporaries. I also enjoyed ripping apart PC's in my folks' basement. Yes, I lived in my folks' basement until after college (and I like Star Trek... but I don't see the connection that everyone else seems to see).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Before graduating high school, I couldn't resist the seductive sales pitch of Sally Struthers and William Shatner so I completed the PC Repair diploma from International Correspondence Schools. And that diploma is unlike anything else. No paper for ICS... no, my diploma came printed and urethaned on 100% particle board.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Ultimately, I found trouble shooting PC's unpleasant. Everyone and their brother wanted me to look at their PC for free and the phone never quit ringing. It made me feel like a box of Smarties at a Weigh Watcher's convention. (Please note that I am morbidly obese and thus have license to make fat jokes).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;As a child, I always wanted to write programs. An acquaintance and programmer, with his keyboard completely gray from cigarette ashes, told me to check out VB - which was a good starting point. I read every book I could and learned how to write database apps. There were still many cracks (okay, canyons) in my knowledge, however.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;It was off to CDI College for their buffet-style learning. At CDI, my programming instructor was extremely knowledgeable and their courseware was up-to-date and without error or omission. Any CDI alumni out there know that I’m being a little tongue-in-cheek. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;But, I learned a lot of great stuff from the other students and from some of the other instructors. Plus, it ultimately landed me a job that has allowed me to continue developing as a developer. That is what I was after more than anything so I really can't complain. Mind you, I still have a few of the canyons.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;As far as academia is concerned, I probably shouldn't be blogging on Multiple Inheritance let-alone programming let-alone procreating let-alone occupying space and consuming oxygen. Fortunately, technology is far more about the passion, the understanding, and the mindset than it is about the piece of paper.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Not that there's anything wrong with a good piece of paper... it's all just one step in the journey where the road extends recursively until we hit our final Stack Overflow Exception and the mighty CLR sends the gc to reclaim us back into the great beyond.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Happy Coding&lt;BR&gt;- Shaun&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;* In Canada, we spell several words with a "u" such as honour, valour, colour&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www.dotnetjunkies.com/WebLog/aggbug.aspx?PostID=133419" width="1" height="1"&gt;</description></item></channel></rss>