<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Architecture</title><link>http://forums.asp.net/16.aspx</link><description>Discuss and debate ASP.NET application designs. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=8&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1275254.aspx</link><pubDate>Wed, 03 May 2006 18:01:43 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1275254</guid><dc:creator>cmay</dc:creator><author>cmay</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1275254.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1275254</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;biswajitdash:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;
&lt;blockquote dir=ltr&gt;
&lt;p&gt;&lt;font size=2&gt;I think you mean the other way around... casting a DerivedClass as a BaseClass.&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Following is down-casting as you are moving away from the base type.&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;BaseClass objRef = null;&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;&amp;nbsp;// BASE TYPE REFERENCE&lt;br /&gt;DerivedClass d = new DerivedClass()&lt;br /&gt;objRef = d;&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;&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; // Still a BASE TYPE REFERENCE&lt;br /&gt;((DerivedClass)objRef).Add(1, 2, 3);&amp;nbsp; // EXPLICIT DOWN-CAST&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;Sorry I thought you were taking about the spot in my code where I was using&amp;nbsp;a DerivedClass as a Base class.&lt;/p&gt;
&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;biswajitdash:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;&lt;/p&gt;
&lt;p&gt;I guess now all agree that, what djdouma wants is not possible in C# and does not make any sense either.&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;Agreed!&lt;/p&gt;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1275199.aspx</link><pubDate>Wed, 03 May 2006 17:16:49 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1275199</guid><dc:creator>biswajitdash</dc:creator><author>biswajitdash</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1275199.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1275199</wfw:commentRss><description>&lt;blockquote dir=ltr&gt;
&lt;p&gt;&lt;font size=2&gt;I think you mean the other way around... casting a DerivedClass as a BaseClass.&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Following is down-casting as you are moving away from the base type.&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;BaseClass objRef = null;&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;&amp;nbsp;// BASE TYPE REFERENCE&lt;br /&gt;DerivedClass d = new DerivedClass()&lt;br /&gt;objRef = d;&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;&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; // Still a BASE TYPE REFERENCE&lt;br /&gt;((DerivedClass)objRef).Add(1, 2, 3);&amp;nbsp; // EXPLICIT DOWN-CAST&lt;/font&gt;&lt;/p&gt;
&lt;blockquote dir=ltr&gt;
&lt;p&gt;&lt;font size=2&gt;But you can't do an implicit upcast when the operation you are trying to execute doesn't exist on the base class, which is what you were trying to do in your code example.&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p dir=ltr&gt;I revisited my post. My mistake. Insteade of compile-time I&amp;nbsp;had written run-time. My intention was compile-time failuer.&lt;/p&gt;
&lt;p dir=ltr&gt;I guess now all agree that, what djdouma wants is not possible in C# and does not make any sense either.&lt;/p&gt;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1275170.aspx</link><pubDate>Wed, 03 May 2006 16:49:29 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1275170</guid><dc:creator>cmay</dc:creator><author>cmay</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1275170.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1275170</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;biswajitdash:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;&lt;font size=3&gt; 
&lt;p&gt;&lt;/p&gt;&lt;/font&gt;
&lt;blockquote dir=ltr&gt;
&lt;p&gt;&lt;font size=2&gt;&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;All confusion has started, from the shadowing concept that you are trying to forcefully introduce into C# language. It simply does not exist in C#. You can never hide a base class method that differs by signature, in C#. So, the what original the poster asked for is not possible in C#. 
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Since it does not exist in this language, whatever code example or logic you try to give, will not hold good from C# point of view. I am not disagreeing from VB.NET point of view.&lt;br /&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;div&gt;I believe I indicated this in my post:&lt;/div&gt;
&lt;div&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;cmay:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Maybe I misspoke here.&lt;/div&gt;
&lt;div&gt;I tried to do it in C# and it would always show the base interface as well (it indicated that the method was from the base class and not the subclass, but still I couldn't hide that inteface).&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;biswajitdash:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt; &lt;/p&gt;
&lt;p&gt;In none of my posts I have told that each and every concrete method implementation has to be declared in an interface or abstract classs. And of course it will be madness to put everything into an interface.&lt;/p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt; 
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When you said "Always program to an abstract/interface and not an implementation." I wasn't sure if you were actually advocating literally &lt;strong&gt;always&lt;/strong&gt; programming against an abstract/interface.&amp;nbsp; Some people &lt;strong&gt;do&lt;/strong&gt; in fact do this, and I'm glad to say we both thing it is madness.&lt;/p&gt;
&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;biswajitdash:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt; &lt;/p&gt;
&lt;p&gt;In your code example you have explicitely &lt;u&gt;down-casted&lt;/u&gt; the BaseClass&amp;nbsp;TYPE REFERENCE into a DerivedClass TYPE. This way the DerivedClass specific method is visible for sure, but this is NOT what real polymorphism is.&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;I think you mean the other way around... casting a DerivedClass as a BaseClass.&lt;/p&gt;
&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;biswajitdash:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt; &lt;/p&gt;
&lt;p&gt;Polymorphism is executing an &lt;u&gt;operation&lt;/u&gt;, without knowing about its specific implementation details in run-time. In OO &lt;u&gt;operation is different from implemented method&lt;/u&gt;. Thing defined as a contract is operation and actual implementation is method. Thats why all polymorphic calls are made from a base type and not a derived type. Its always based on implicit &lt;u&gt;up-casting&lt;/u&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;But you can't do an implicit upcast when the operation you are trying to execute doesn't exist on the base class, which is what you were trying to do in your code example.&lt;/p&gt;
&lt;p&gt;BaseClass has Add w/ two parameters,&amp;nbsp; DerivedClass includes Add with 3 parameters.&lt;/p&gt;
&lt;p&gt;You can't say:&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;pre class=coloredcode&gt;	    BaseClass b = &lt;span class=kwd&gt;new&lt;/span&gt; BaseClass();
            DerivedClass d = &lt;span class=kwd&gt;new&lt;/span&gt; DerivedClass();
            BaseClass objRef = &lt;span class=kwd&gt;null&lt;/span&gt;;

            &lt;span class=cmt&gt;// Polymorphic call here. Will fail. Because 
            // type BaseClass does not have any Add() 
            // method that takes 3 arguments.&lt;/span&gt;
            objRef = d;

            objRef.Add(1, 2, 3); &lt;span class=cmt&gt;// Will fail.&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;That will never work, and it has nothing to do with shadows or new.&amp;nbsp; If you were working in Javascript the above code would work, but in C#, or VB.Net or Java this won't even compile.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1275152.aspx</link><pubDate>Wed, 03 May 2006 16:30:06 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1275152</guid><dc:creator>Caddre</dc:creator><author>Caddre</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1275152.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1275152</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;biswajitdash:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;And how exactly you make methods shadow in C#, where the method signature itself differs? Can you give working example code?&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;The link below is&amp;nbsp;a blog entry in Dino's blog and the replies&amp;nbsp;seems to imply there is no equivalent of Shadow in C#.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.asp.net/despos/archive/2004/03/10/86995.aspx"&gt;http://weblogs.asp.net/despos/archive/2004/03/10/86995.aspx&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1275092.aspx</link><pubDate>Wed, 03 May 2006 15:40:36 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1275092</guid><dc:creator>TAsunder</dc:creator><author>TAsunder</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1275092.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1275092</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;cmay:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;
&lt;div&gt;You don't lose any polymorphism doing this.&amp;nbsp; That is why the method shadows the inherited classes methods.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;Obviously I wasn't trying to put a lot of real world relevance into my example with my Add method.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;The issue is that there may be times when you want to inherit from a class and have a simliar named method with a different signature, maybe do different things, without breaking anything in the base class.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;You don't always have access to the source code to change the class you are inheriting from, and you don't always want to change the base class anyway.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;If I use shadows on a method and you pass the object polymorphically as its base class's type, then the base class "Add" method will be available, not the shadows method, so polymorphism is fully available.&lt;/div&gt;
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;But this is not what his sample code seemed to indicate.&amp;nbsp; Take a look at it again.&amp;nbsp; From what I can see, he has an add method that does nothing in the base class, and exists only as a signature of what the inherited classes have to do, even though it will be with different parameters always.&amp;nbsp; The class is fully abstract.&amp;nbsp; It might be that you interpreted my post as an answer to you and not the OP?&amp;nbsp; I agree with your solution as a solution to something else, but I don't think it has to do with what he is trying to accomplish.&lt;/p&gt;
&lt;p&gt;It's true, you can in theory achieve polymorphism with shadows, but not in the case of the original post.&amp;nbsp; In the original post, the add method does nothing in the base class.&amp;nbsp; You can't call it at all and have anything meaningful done, unless the sub classes override the add with no parameters.&lt;/p&gt;
&lt;p&gt;It is the OP's scenario that violates polymorphism and makes no sense.&amp;nbsp; The add method is abstract, and won't ever be called.&amp;nbsp; Seems like he wants to structure his app so that all DAL objects inherit from a base class that has Add and Delete with no parameters, but those will never be called.&amp;nbsp; For polymorphic operations, a method should be able to operate on the base class and have the base class methods do something useful.&amp;nbsp; In this example, that is not the case.&amp;nbsp; I can't write a method that takes in a "Base" object and then call add, because any particular sub class has its own version of what has to be passed in to do an add.z&lt;/p&gt;
&lt;p&gt;What is the purpose then?&amp;nbsp; It's not like something is going to call Add() with no parameters.&amp;nbsp; Always he will have to call Add with specific parameters.&amp;nbsp; Which totally defeats the purpose of having an add in the first place.&lt;/p&gt;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1275082.aspx</link><pubDate>Wed, 03 May 2006 15:35:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1275082</guid><dc:creator>biswajitdash</dc:creator><author>biswajitdash</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1275082.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1275082</wfw:commentRss><description>&lt;font size=3&gt;
&lt;p&gt;&lt;u&gt;Answering the original post&lt;/u&gt;: Either define overloaded Add() methods into an abstract&amp;nbsp;base class, or forget about inheritance and go by concrete type calls. The question&amp;nbsp;does not have any straight-forward inheritance based solution in C#.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Answering the cmay's last post&lt;/u&gt;:&lt;/p&gt;&lt;/font&gt;
&lt;blockquote dir=ltr&gt;
&lt;p&gt;&lt;font size=2&gt;I am not sure where the disconnect here is.&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;All confusion has started, from the shadowing concept that you are trying to forcefully introduce into C# language. It simply does not exist in C#. You can never hide a base class method that differs by signature, in C#. So, the what original the poster asked for is not possible in C#.&lt;/p&gt;
&lt;p&gt;Since it does not exist in this language, whatever code example or logic you try to give, will not hold good from C# point of view. I am not disagreeing from VB.NET point of view.&lt;/p&gt;
&lt;p&gt;I have been answering everything keeping in mind the original post and the shadow concept that came in. Because this concept is taking the original poster in the wrong direction. &lt;u&gt;Original question was in C#&lt;/u&gt;.&lt;/p&gt;
&lt;blockquote dir=ltr&gt;
&lt;p&gt;&lt;font size=2&gt;You can't always program to an abstract, unless you are willing to assign every method to an interface.&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;In none of my posts I have told that each and every concrete method implementation has to be declared in an interface or abstract classs. And of course it will be madness to put everything into an interface.&lt;/p&gt;
&lt;blockquote dir=ltr&gt;
&lt;p&gt;&lt;font size=2&gt;This is exactly what my code example did!&amp;nbsp; The BaseClass interface is used when you cast a DerivedClass as BaseClass.&amp;nbsp; This is one of the basic principles of OO.&amp;nbsp; This is polymorphism.&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;In your code example you have explicitely &lt;u&gt;down-casted&lt;/u&gt; the BaseClass&amp;nbsp;TYPE REFERENCE into a DerivedClass TYPE. This way the DerivedClass specific method is visible for sure, but this is NOT what real polymorphism is.&lt;/p&gt;
&lt;p&gt;Polymorphism is executing an &lt;u&gt;operation&lt;/u&gt;, without knowing about its specific implementation details in run-time. In OO &lt;u&gt;operation is different from implemented method&lt;/u&gt;. Thing defined as a contract is operation and actual implementation is method. Thats why all polymorphic calls are made from a base type and not a derived type. Its always based on implicit &lt;u&gt;up-casting&lt;/u&gt;.&lt;/p&gt;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1274941.aspx</link><pubDate>Wed, 03 May 2006 13:52:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1274941</guid><dc:creator>cmay</dc:creator><author>cmay</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1274941.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1274941</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;biswajitdash:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;
&lt;blockquote dir=ltr&gt;
&lt;p&gt;What you are telling in essence means that "Prgram to the concrete implementation and not the abstract/interface".&lt;br /&gt;The actual principle is - "Always program to an abstract/interface and not an implementation." Thats how polymorphiism is used. Otherwise why does the concept of &lt;font color=#0000ff&gt;interface&lt;/font&gt; exist?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;I am not sure where the disconnect here is.&lt;/p&gt;
&lt;p&gt;You can't always program to an abstract, unless you are willing to assign every method to an interface.&amp;nbsp; What if Employee inherits from Person?&amp;nbsp; Employee has a "givePayRaise" method.&amp;nbsp; How are you going to "program to the abstract" and be able to execute that method?&amp;nbsp; You can't, unless you go nuts and make every class implement an interface for no reason.&lt;/p&gt;
&lt;p&gt;Polymorphism is used by allowing you to treate CONCRETE (or even abstract types, so long as they extend from another class) implementations as more simple GENERIC objects / interfaces.&lt;/p&gt;
&lt;p&gt;This is exactly what my code example did!&amp;nbsp; The BaseClass interface is used when you cast a DerivedClass as BaseClass.&amp;nbsp; This is one of the basic principles of OO.&amp;nbsp; This is polymorphism.&lt;/p&gt;
&lt;p&gt;I really don't know where you see a problem with this.&amp;nbsp; You can never call "givePayRaise" off a Person object unless that Person is really an Employee.&amp;nbsp; The Person interface doesn't have "givePayRaise".&amp;nbsp; It is this that you were trying to do in your first code example.&lt;/p&gt;
&lt;p&gt;"Prgram to the concrete implementation and not the abstract/interface".&amp;nbsp; Unless you NEED to program against the concrete implementation as I showed above (givePayRaise), then you HAVE to program against the concrete implementation.&amp;nbsp; My code example shows you can program to the abstract/interface if you want and it works just fine.&lt;/p&gt;
&lt;p&gt;"Always program to an abstract/interface and not an implementation." Thats how polymorphiism is used. Otherwise why does the concept of &lt;font color=#0000ff&gt;interface&lt;/font&gt; exist?&amp;nbsp; Any code you write against the BaseClass will work just fine if you use DerivedClass.&amp;nbsp; THAT is how polymorphism works.&amp;nbsp; If you are suggesting that the concept of interfaces exists so that you never have to work with a concrete class, then I would disagree with your way of programming.&amp;nbsp; Implementing interfaces allows a class to be used polymorphically in multiple cases, are are very important in languages like C#/Vb.Net/Java, that don't support multiple inheritance.&lt;/p&gt;
&lt;p&gt;If you want to take the position (I would strongly disagree with it) that you need to have every class implement an interface so you can ALWAYS program against an interface or abstract base class, then I would first say that I disagree with that philosophy, and second that you can STILL do that just fine with my code example: you can still do that type of design using shadows.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1274639.aspx</link><pubDate>Wed, 03 May 2006 07:05:23 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1274639</guid><dc:creator>biswajitdash</dc:creator><author>biswajitdash</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1274639.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1274639</wfw:commentRss><description>&lt;blockquote dir=ltr&gt;
&lt;p&gt;&lt;font size=2&gt;Sorry but your code example is backwards in terms of understanding how polymorphism and LSP works.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size=2&gt;Polymorphism works by allowing you to say that a DerivedClass can be used as a BaseClass.&amp;nbsp; But you are trying to use a BaseClass as a DerivedClass.&amp;nbsp; Polymorphism doesn't work in that direction.&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;What you are telling in essence means that "Prgram to the concrete implementation and not the abstract/interface". Is it? Thats not correct.&amp;nbsp;I guess most in this forum will disagree on what you are telling. &lt;/p&gt;
&lt;p&gt;The actual principle is - "Always program to an abstract/interface and not an implementation." Thats how polymorphiism is used. Otherwise why does the concept of &lt;font color=#0000ff&gt;interface&lt;/font&gt; exist?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1274571.aspx</link><pubDate>Wed, 03 May 2006 05:10:22 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1274571</guid><dc:creator>cmay</dc:creator><author>cmay</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1274571.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1274571</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;biswajitdash:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt; 
&lt;blockquote dir=ltr&gt;
&lt;p&gt;&lt;font size=2&gt;You don't lose any polymorphism doing this.&amp;nbsp; That is why the method shadows the inherited classes methods.&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;What TAsunder asked is correct. Look at the following code block to explain the polymorphic scenario better. The VB.NET way of shadowing really does not satisfy any polymorphism. Assume that the classes are written in VB.NET library and referred from a C# client.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;font face="Courier New" size=2&gt;' VB.NET Class Library&lt;br /&gt;Public Class BaseClass&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Function Add(ByVal i As Integer, &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ByVal j As Integer) As Integer&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return i + j&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Function&lt;br /&gt;End Class&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;font face="Courier New" size=2&gt;Public Class DerivedClass&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Inherits BaseClass&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Shadows Function Add(ByVal i As Integer, &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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ByVal j As Integer, &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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ByVal k As Integer) As Integer&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return MyBase.Add(i, j) + k&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Function&lt;br /&gt;End Class&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;// C# Class Library&lt;br /&gt;public class ClientClass&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void Main()&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; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BaseClass b = new BaseClass();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DerivedClass d = new DerivedClass();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BaseClass objRef = null;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Polymorphic call here. Will work fine.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objRef = b;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objRef.Add(1, 2); // Will work.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Polymorphic call here. Will fail. Because &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // type BaseClass does not have any Add()&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // method that takes 3 arguments.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objRef = _d;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objRef.Add(1, 2, 3); // Will fail.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;So, a polymorphic call in run-time will fail. Also following shadowing technique in real-life violates LSP at the best. Any design using this must be avoided.&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry but your code example is backwards in terms of understanding how polymorphism and LSP works.&lt;/p&gt;
&lt;p&gt;Polymorphism works by allowing you to say that a DerivedClass can be used as a BaseClass.&amp;nbsp; But you are trying to use a BaseClass as a DerivedClass.&amp;nbsp; Polymorphism doesn't work in that direction.&lt;/p&gt;
&lt;p&gt;Your line of code:&lt;br /&gt;&lt;font face="Courier New" size=2&gt;objRef.Add(1, 2, 3); // Will fail.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;Of course it will fail.&amp;nbsp; It won't even compile.&amp;nbsp; objRef is a BaseClass.&amp;nbsp; BaseClass doesn't have a method "Add" that takes 3 parameters.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;What if DerivedClass defines a method "Subtract".&amp;nbsp; objRef won't have that either.&amp;nbsp; It's the same thing.&amp;nbsp; Base Classes don't know about the classes that inherit from them.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;But if you case objRef as a DerivedClass, then you can call Add with 2 or 3 parameters, just as you would expect to.&lt;/p&gt;
&lt;p&gt;If what you coded worked (objRef.Add(1,2,3)) then THAT is what would break LSP.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;But LSP is not violated.&amp;nbsp; I modified your code a little to show that LSP is not violated, and polymorphism remains fully functional.&lt;/p&gt;
&lt;p&gt;See my code example to clear this up:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&amp;nbsp;&lt;pre class=coloredcode&gt;&lt;span class=cmt&gt;' VB.NET Class Library
&lt;/span&gt;
&lt;span class=kwd&gt;Public Class&lt;/span&gt; BaseClass
    &lt;span class=kwd&gt;Public Function&lt;/span&gt; Add(&lt;span class=kwd&gt;ByVal&lt;/span&gt; i &lt;span class=kwd&gt;As Integer&lt;/span&gt;, _
                        &lt;span class=kwd&gt;ByVal&lt;/span&gt; j &lt;span class=kwd&gt;As Integer&lt;/span&gt;) &lt;span class=kwd&gt;As Integer
        Return&lt;/span&gt; i + j
    &lt;span class=kwd&gt;End Function

    Public Function&lt;/span&gt; LSP() &lt;span class=kwd&gt;As String
        Return&lt;/span&gt; &lt;span class=st&gt;"I am LSP compliant"&lt;/span&gt;
    &lt;span class=kwd&gt;End Function
End Class


Public Class&lt;/span&gt; DerivedClass
    &lt;span class=kwd&gt;Inherits&lt;/span&gt; BaseClass

    &lt;span class=kwd&gt;Public Shadows Function&lt;/span&gt; Add(&lt;span class=kwd&gt;ByVal&lt;/span&gt; i &lt;span class=kwd&gt;As Integer&lt;/span&gt;, _
                                &lt;span class=kwd&gt;ByVal&lt;/span&gt; j &lt;span class=kwd&gt;As Integer&lt;/span&gt;, _
                                &lt;span class=kwd&gt;ByVal&lt;/span&gt; k &lt;span class=kwd&gt;As Integer&lt;/span&gt;) &lt;span class=kwd&gt;As Integer
        Return MyBase&lt;/span&gt;.Add(i, j) + k
    &lt;span class=kwd&gt;End Function

    Public Shadows Function&lt;/span&gt; LSP() &lt;span class=kwd&gt;As String
        Return&lt;/span&gt; &lt;span class=st&gt;"I am NOT LSP compliant, bad programmer"&lt;/span&gt;
    &lt;span class=kwd&gt;End Function
End Class&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&amp;nbsp;&lt;pre class=coloredcode&gt;&lt;span class=kwd&gt;static void&lt;/span&gt; Main(&lt;span class=kwd&gt;string&lt;/span&gt;[] args)
        {
            
            BaseClass b = &lt;span class=kwd&gt;new&lt;/span&gt; BaseClass();
            DerivedClass d = &lt;span class=kwd&gt;new&lt;/span&gt; DerivedClass();
            BaseClass objRef = &lt;span class=kwd&gt;null&lt;/span&gt;;

            &lt;span class=cmt&gt;// Polymorphic call here. Will work fine.&lt;/span&gt;
            objRef = b;
            objRef.Add(1, 2); &lt;span class=cmt&gt;// Will work.

            // Polymorphic call here. Will fail. Because 
            // type BaseClass does not have any Add() 
            // method that takes 3 arguments.&lt;/span&gt;
            objRef = d;

            
            &lt;span class=cmt&gt;//objRef.Add(1, 2, 3); // Will fail.
            /**************
             * My Comments: of course this will fail... 
             * It will fail at compile time.  objRef is a BaseClass. 
             * BaseClass doesn't have Add(i,i,i)  */

            // this will work just fine.&lt;/span&gt;
            ((DerivedClass)objRef).Add(1, 2, 3);

            &lt;span class=cmt&gt;// lets make sure LSP is not violated&lt;/span&gt;
            Console.WriteLine(testLsp(b));
            Console.WriteLine(testLsp(d));
            Console.WriteLine(testLsp(objRef));
            Console.WriteLine(testLsp((DerivedClass)objRef));
            Console.WriteLine(&lt;span class=st&gt;"All passed"&lt;/span&gt;);
            Console.Read();
        }

        &lt;span class=kwd&gt;static string&lt;/span&gt; testLsp(BaseClass b)
        {
            &lt;span class=kwd&gt;return&lt;/span&gt; b.LSP();
        }&lt;/pre&gt;&amp;nbsp;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1274545.aspx</link><pubDate>Wed, 03 May 2006 04:20:19 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1274545</guid><dc:creator>biswajitdash</dc:creator><author>biswajitdash</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1274545.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1274545</wfw:commentRss><description>&lt;blockquote dir=ltr&gt;
&lt;p&gt;&lt;font size=2&gt;You don't lose any polymorphism doing this.&amp;nbsp; That is why the method shadows the inherited classes methods.&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;What TAsunder asked is correct. Look at the following code block to explain the polymorphic scenario better. The VB.NET way of shadowing really does not satisfy any polymorphism. Assume that the classes are written in VB.NET library and referred from a C# client.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;font face="Courier New" size=2&gt;' VB.NET Class Library&lt;br /&gt;Public Class BaseClass&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Function Add(ByVal i As Integer, &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ByVal j As Integer) As Integer&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return i + j&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Function&lt;br /&gt;End Class&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;font face="Courier New" size=2&gt;Public Class DerivedClass&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Inherits BaseClass&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Shadows Function Add(ByVal i As Integer, &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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ByVal j As Integer, &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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ByVal k As Integer) As Integer&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return MyBase.Add(i, j) + k&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Function&lt;br /&gt;End Class&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;// C# Class Library&lt;br /&gt;public class ClientClass&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void Main()&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; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BaseClass b = new BaseClass();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DerivedClass d = new DerivedClass();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BaseClass objRef = null;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Polymorphic call here. Will work fine.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objRef = b;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objRef.Add(1, 2); // Will work.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Polymorphic call here. Will fail. Because &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // type BaseClass does not have any Add()&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // method that takes 3 arguments.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objRef = _d;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objRef.Add(1, 2, 3); // Will fail.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size=2&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;So, a polymorphic call in run-time will fail. Also following shadowing technique in real-life violates LSP at the best. Any design using this must be avoided.&lt;/p&gt;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1274174.aspx</link><pubDate>Tue, 02 May 2006 18:57:40 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1274174</guid><dc:creator>cmay</dc:creator><author>cmay</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1274174.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1274174</wfw:commentRss><description>&lt;div&gt;You don't lose any polymorphism doing this.&amp;nbsp; That is why the method shadows the inherited classes methods.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;Obviously I wasn't trying to put a lot of real world relevance into my example with my Add method.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;The issue is that there may be times when you want to inherit from a class and have a simliar named method with a different signature, maybe do different things, without breaking anything in the base class.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;You don't always have access to the source code to change the class you are inheriting from, and you don't always want to change the base class anyway.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;If I use shadows on a method and you pass the object polymorphically as its base class's type, then the base class "Add" method will be available, not the shadows method, so polymorphism is fully available.&lt;/div&gt;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1274157.aspx</link><pubDate>Tue, 02 May 2006 18:42:54 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1274157</guid><dc:creator>TAsunder</dc:creator><author>TAsunder</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1274157.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1274157</wfw:commentRss><description>&lt;p&gt;I don't get it.&amp;nbsp; Why do you want to do this?&amp;nbsp; It makes no sense.&amp;nbsp; Is it just so that when you type the . after the object it shows an add method?&amp;nbsp; It really does not offer you any of the flexibility of polymorphism when you do this.&amp;nbsp; If your base method is to be at all meaningful or useful and not just wasted code to confuse developers, you need to abstract the method parameters too.&lt;/p&gt;
&lt;p&gt;Maybe you need an AddParameters class.&amp;nbsp; By default this has no members.&amp;nbsp; In your individual Add() methods you make sure that the class passed in to the Add method is of the minimal type needed (i.e. you need an object that inherits from AddParameters that has an Int).&lt;/p&gt;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1273858.aspx</link><pubDate>Tue, 02 May 2006 16:22:50 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1273858</guid><dc:creator>cmay</dc:creator><author>cmay</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1273858.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1273858</wfw:commentRss><description>&lt;div&gt;Maybe I misspoke here.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;I tried to do it in C# and it would always show the base interface as well (it indicated that the method was from the base class and not the subclass, but still I couldn't hide that inteface).&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;In VB.Net you can indeed hid the interface of the base class using Shadows.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;Maybe someone else can tell me if there is no way to do this with C#.&amp;nbsp; I figured b/c you could do it in VB you could in C#.&lt;/div&gt;&amp;nbsp;&lt;pre class=coloredcode&gt;&lt;span class=kwd&gt;Public Class&lt;/span&gt; Base
    &lt;span class=kwd&gt;Public Function&lt;/span&gt; Add(&lt;span class=kwd&gt;ByVal&lt;/span&gt; i &lt;span class=kwd&gt;As Integer&lt;/span&gt;, &lt;span class=kwd&gt;ByVal&lt;/span&gt; n &lt;span class=kwd&gt;As Integer&lt;/span&gt;) &lt;span class=kwd&gt;As Integer
        Return&lt;/span&gt; i + n
    &lt;span class=kwd&gt;End Function
End Class

Public Class&lt;/span&gt; SubClass
    &lt;span class=kwd&gt;Inherits&lt;/span&gt; Base

    &lt;span class=kwd&gt;Public Shadows Function&lt;/span&gt; Add(&lt;span class=kwd&gt;ByVal&lt;/span&gt; i &lt;span class=kwd&gt;As Integer&lt;/span&gt;, &lt;span class=kwd&gt;ByVal&lt;/span&gt; x &lt;span class=kwd&gt;As Integer&lt;/span&gt;, &lt;span class=kwd&gt;ByVal&lt;/span&gt; y &lt;span class=kwd&gt;As Integer&lt;/span&gt;) &lt;span class=kwd&gt;As Integer
        Return MyBase&lt;/span&gt;.Add(i, x) + y
    &lt;span class=kwd&gt;End Function
End Class&lt;/span&gt;&lt;/pre&gt;&amp;nbsp;&amp;nbsp;&lt;pre class=coloredcode&gt;    &lt;span class=kwd&gt;public abstract class&lt;/span&gt; Abst
    {
        &lt;span class=kwd&gt;public abstract string&lt;/span&gt; AbstMethod();

        &lt;span class=kwd&gt;public  string&lt;/span&gt; Add(&lt;span class=kwd&gt;int&lt;/span&gt; i, &lt;span class=kwd&gt;int&lt;/span&gt; n)
        {
            &lt;span class=kwd&gt;int&lt;/span&gt; ret = (i + n);

            &lt;span class=kwd&gt;return&lt;/span&gt; ret.ToString();
        }
    }

    &lt;span class=kwd&gt;public class&lt;/span&gt; Conc : Abst
    {
        &lt;span class=kwd&gt;public override string&lt;/span&gt; AbstMethod()
        {  
            &lt;span class=kwd&gt;return&lt;/span&gt; &lt;span class=st&gt;"Whatever"&lt;/span&gt;;
        }
        
        &lt;span class=kwd&gt;public new string&lt;/span&gt; Add(&lt;span class=kwd&gt;int&lt;/span&gt; i, &lt;span class=kwd&gt;int&lt;/span&gt; n, &lt;span class=kwd&gt;int&lt;/span&gt; x)
        {
            &lt;span class=kwd&gt;int&lt;/span&gt; basevalue = &lt;span class=kwd&gt;int&lt;/span&gt;.Parse(&lt;span class=kwd&gt;base&lt;/span&gt;.Add(i, n));
            basevalue = basevalue + x;
            &lt;span class=kwd&gt;return&lt;/span&gt; basevalue.ToString();
        }
    }&lt;/pre&gt;&amp;nbsp;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1273842.aspx</link><pubDate>Tue, 02 May 2006 16:10:34 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1273842</guid><dc:creator>djdouma</dc:creator><author>djdouma</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1273842.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1273842</wfw:commentRss><description>&lt;p&gt;&lt;font face=Tahoma size=2&gt;Ido, thanks for your comments.&amp;nbsp; Would you be able to provide a code example which follows along the lines of what I originally posted (two methods, Delete &amp;amp; Add, with two Classes implementing Add with two different parameter lists)?&amp;nbsp; I work better with examples &lt;img src="/emoticons/emotion-5.gif" alt="Wink [;)]" /&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class=coloredcode&gt;&lt;span class=kwd&gt;public abstract class&lt;/span&gt; BaseObject 
{ 

 &lt;span class=kwd&gt;public abstract void&lt;/span&gt; Add(); 

 &lt;span class=kwd&gt;public abstract void&lt;/span&gt; Delete(&lt;span class=kwd&gt;int&lt;/span&gt; Id); 
} 
&lt;span class=kwd&gt;public class&lt;/span&gt; ChildObject1 : BaseObject 
{ 

 &lt;span class=kwd&gt;public override void&lt;/span&gt; Add(&lt;span class=kwd&gt;string&lt;/span&gt; Name, &lt;span class=kwd&gt;string&lt;/span&gt; Desc) 
 { 
 } 

 &lt;span class=kwd&gt;public override void&lt;/span&gt; Delete(&lt;span class=kwd&gt;int&lt;/span&gt; Id) 
 { 
 } 
} 
&lt;span class=kwd&gt;public class&lt;/span&gt; ChildObject2 : BaseObject 
{ 

 &lt;span class=kwd&gt;public override void&lt;/span&gt; Add(&lt;span class=kwd&gt;string&lt;/span&gt; Name) 
 { 
 } 

 &lt;span class=kwd&gt;public override void&lt;/span&gt; Delete(&lt;span class=kwd&gt;int&lt;/span&gt; Id) 
 { 
 } 
} 
&lt;span class=kwd&gt;struct&lt;/span&gt; TestModule 
{ 

 &lt;span class=kwd&gt;void&lt;/span&gt; Main() 
 { 
   ChildObject1 child1 = &lt;span class=kwd&gt;new&lt;/span&gt; ChildObject1(); 
   child1.add(&lt;span class=st&gt;"Testing Child1"&lt;/span&gt;); 
   ChildObject2 child2 = &lt;span class=kwd&gt;new&lt;/span&gt; ChildObject2(); 
   child2.add(&lt;span class=st&gt;"Testing Child2"&lt;/span&gt;, &lt;span class=st&gt;"My Description"&lt;/span&gt;); 
 } 
}&lt;/pre&gt;&amp;nbsp;</description></item><item><title>Re: Abstract Class &amp; Inheritance</title><link>http://forums.asp.net/thread/1273806.aspx</link><pubDate>Tue, 02 May 2006 15:44:48 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1273806</guid><dc:creator>idof</dc:creator><author>idof</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1273806.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=16&amp;PostID=1273806</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;As you've been explained, this is not the usual use of an abstract class. BTW, if you wish to do the above, you'd better use interfaces (call it IUpdatableObject for example).&lt;/p&gt;
&lt;p&gt;As for the parameters - if you use .net 2.0, you can use generics and declare the parameter type as T.&lt;/p&gt;
&lt;p&gt;for example:&lt;/p&gt;
&lt;p&gt;interface IUpdatableObject&amp;lt;T&amp;gt;&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;void update(T newData);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;class Implementor : IUpdatableObject&amp;lt;string&amp;gt;&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;public void update(string newData)&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;If you need to use multiple parameters, just declare a custom class/struct to hold those parameters (which actually makes it a data structure).&lt;/p&gt;
&lt;p&gt;Best of luck,&lt;/p&gt;
&lt;p&gt;Ido.&lt;/p&gt;</description></item></channel></rss>