Sharon,
What you want to do was, once upon a time, possibly legal in .NET.
However, it turns out you cannot change the access level of a method
in a derived class (my earlier unfounded assertion to the contrary
notwithstanding), and have it hide the underlying method which is in
effect what you want to do.

Now there is a good reason for this -- it would really screw around
with polymorphism.  Any class derived from a base class is expected to
have its public members, so the rest of the code doesn't have to know
anything specifc about the derived class to use it.  If you start
hiding methods, well, there is anarchy.

Here is a more formal write up...
http://www.eventhelix.com/RealtimeMantra/Object_Oriented/liskov_substitution_principle.htm

David's suggestion is correct, you probably want to rethink your design.

And I should stop trying answer questions on Friday afternoons.

Sorry to raise your hopes.

On 1/29/06, David Lanouette <[EMAIL PROTECTED]> wrote:
> So, let me see if I understand your question.
>
> You want the client code to be able to do either of these:
> BaseClass b = new BaseClass();
> b.Method1(a, b);
> b.Method2(a);
>
> Derivedclass1 d1 = new Derivedclass1();
> d1.Method1(a, b);
> d1.Method2(a);
>
> Derivedclass2 d2 = new Derivedclass2();
> d2.Method1(a, b);
>
>
> But, you don't want to be able to do this?
> d2.Method2(a);
>
>
> If that is the case, you can't do it because Method2 is part of the
> class (to my knowledge).  You could however do this:
> Derivedclass2 : Baseclass
> {
>         public override Method2(a)
>         {
>                 throw new System.NotImplementedException();
>         }
>
> }
>
> That would atleast throw an exception if the client tried to call it.
>
> However, I'd consider revising your design if you feel that you need to do 
> this.
>
>
> HTH.
>
> >  On 1/27/06, Sharon <[EMAIL PROTECTED]> wrote:
> >  > Hi All,
> >  > This is the format of classes I Have.
> >  >
> >  > BaseClass
> >  > {
> >  > public Method1(a,b)
> >  > public Method2(a)
> >  > }
> >  >
> >  > Derivedclass1 : Baseclass
> >  > {
> >  > }
> >  >
> >  > Derivedclass2 : Baseclass
> >  > {
> >  > }
> >  >
> >  > I want Derivedclass2 not to use the method2 from the base class. In other
> > words anyone using Derivedclass2 should not have access to method2. I am
> > convinced on my end that it cannot be achieved but I was proved wrong more
> > then once, So I am here for second opinions.
>
>
> --
> ______________________________
> - David Lanouette
> - [EMAIL PROTECTED]
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>


--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNet2/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to