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...
update:I thought it will be interesting to write my notes from the Designing Inheritance Hierarchies video, so here it is:
public interface IMyInterface { void MyMethod(); }
Now let's assume that I have MyClass which inherits from IMyInterface. If I'll decide
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 { get { // return B class instance. } } }
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.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2009, Oren Ellenbogen
<= Contact me via E-mail
newtelligence dasBlog 2.2.8279.16125