Re: OOP???

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Dean L. Howen (coldman_at_hotpop.com)
Date: 03/01/05


Date: Tue, 1 Mar 2005 22:24:32 +0700

ok, I agree to hide property. But could you tell me the method to "hide"
property which I've not known before.

"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1c8c0c74f3ffa90698bde9@msnews.microsoft.com...
> Dean L. Howen <coldman@hotpop.com> wrote:
>> As the class I describe above, I have some questions. Please help me:
>> Q1: I just want the property "Message" is used directly when create
>> instance
>> of class Parent
>
> <snip>
>
>> but, I don't want it (the property "Message") be used if create instance
>> of
>> class Child
>
> In that case Child shouldn't derive from Parent, as you don't want them
> to be usable in the same way. It breaks Liskov's Substitutability
> Principle. Besides, someone could do:
>
> Parent foo = new Child();
> foo.Message = ...; and the compiler couldn't know the difference.
>
>> Q2: could we override properties in inheritance class.
>
> Yes, so long as the property is declared to be virtual - and so long as
> you use the same signature.
>
>> I want override
>> System.Data.DataTable.Rows in System.Data.DataTable class
>
> You can't do that, as the Rows property isn't virtual. You could *hide*
> the property, but you can't override it.
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



Relevant Pages