Great Videos with Brad Abrams and other .NET experts.

Read this post by the legendary Brad Abrams and watch the videos you’re interested at. I’ve seen “Designing Inheritance Hierarchies” and Enabling Development Tools” videos (for the moment) and I promise that you can learn a thing or two as well ;-).

Happy learning…

I thought it will be interesting to write my notes from the Designing Inheritance Hierarchies video, so here it is:

  1. Interfaces don’t allow backward compatibility ! Let’s assume we have to following interface

          public interface IMyInterface
               void MyMethod();

    Now let’s assume that I have MyClass which inherits from IMyInterface. If I’ll decide to add a new 
    signature to the interface, MyClass will be broken (TypeLoadException will be thrown in compile time).

  2. Base Classes version better than interfaces – if MyClass was inherited from MyBaseClass instead of IMyInterface I wouldn’t have a problem to add new signatures to the class without causing the inherited classes to break.
  3. If you must inherit from 2 “root” classes, the recommended pattern is:

          public class A {}
          public class B {}
          public class C : A // Let’s assume that A is “more” root to C than B
             public B BInstance
                    // return B class instance.

  4. You can use Interfaces in “private” way via Explicit declaration:

      public interface IMyInterface
         string ReturnSomething();

      public class MyClass : IMyInterface
          string IMyInterface.ReturnSomething()
            return “oren”;

      Now, when you create a new instance of MyClass, you won’t see 
          ReturnSomething method on the public view:


      Though, you can always call this method simply by casting c to IMyInterface:


      This can be useful if you want to “hide” some of the interfaces’ abilities in your 
          class. This is recommendable if you don’t want the “clients” to use a 
          certain behavior directly
through the class. 
         .NET framework use this ability in Int32 structure:

      int i = 5;
      i.ToString() // work
      i.ToInt32(); // don’t work.
      ((IConvertible)i).ToInt32(); // work !

      “ This member supports the .NET Framework infrastructure and 
        is not intended to be used directly from your code. ” 
      (from MSDN, Int32.IConvertible.ToInt32 method)


I hope I’ve managed to give you some insights, just enough to convince you to start viewing these videos.


Oren Ellenbogen