Partial implementation of interface

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Advait Mohan Raut

    #1

    Partial implementation of interface

    Hello friends,
    I am new to C#. I have some fundamental doubt. Please, try to answer
    it.

    1) Ltes say, IFace is an interface which has proto of two methods.
    class A implements IFase.

    interface IFace
    {
    void func1(...) {.....}
    void func2(...) {.....}
    }

    class A : IFace
    {
    void func1(...) {.....}
    void func2(...) {.....}
    }

    class B : A, IFace
    {
    ....
    }

    Now the question is, in the defination of class B is it neccesory to
    implement all two members of IFace. I dont want to change defination
    of func1( ) which is from A to B. Or implementation of only one will
    solve the problem ?

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Partial implementation of interface

    Advait,

    Class B, if it does not define anything else, will implement the
    interface IFace (you shouldn't need it in the declaration of B, as a matter
    of fact).

    If you want to provide an implementation of one of the methods defined
    in IFace, then you will need to declare the methods in A as virtual, so that
    B can override them.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Advait Mohan Raut" <advait.m.raut@ gmail.comwrote in message
    news:1190387698 .519646.325470@ t8g2000prg.goog legroups.com...
    Hello friends,
    I am new to C#. I have some fundamental doubt. Please, try to answer
    it.
    >
    1) Ltes say, IFace is an interface which has proto of two methods.
    class A implements IFase.
    >
    interface IFace
    {
    void func1(...) {.....}
    void func2(...) {.....}
    }
    >
    class A : IFace
    {
    void func1(...) {.....}
    void func2(...) {.....}
    }
    >
    class B : A, IFace
    {
    ...
    }
    >
    Now the question is, in the defination of class B is it neccesory to
    implement all two members of IFace. I dont want to change defination
    of func1( ) which is from A to B. Or implementation of only one will
    solve the problem ?
    >

    Comment

    • Advait Mohan Raut

      #3
      Re: Partial implementation of interface

      On Sep 21, 8:24 pm, "Nicholas Paldino [.NET/C# MVP]"
      <m...@spam.guar d.caspershouse. comwrote:
      Advait,
      >
      Class B, if it does not define anything else, will implement the
      interface IFace (you shouldn't need it in the declaration of B, as a matter
      of fact).
      >
      If you want to provide an implementation of one of the methods defined
      in IFace, then you will need to declare the methods in A as virtual, so that
      B can override them.
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - m...@spam.guard .caspershouse.c om
      >
      But is it possible that, a method delared in an interface to be
      implemented as virtual ?

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Partial implementation of interface

        Advait Mohan Raut <advait.m.raut@ gmail.comwrote:
        Than you, Nicholas Paldino for the nice information. Actuly I came to
        conclusion the one cannot override selected methods of the interface,
        because in the offline help of VS 2005 (i.e. C# Reference) they have
        stated that 'override' will work only if the base class proto is
        either 'override' or 'abstract' or 'virtual' .
        But when you implement it in the base class you can make it virtual or
        abstract. If you do that, you can override it in the derived class.

        --
        Jon Skeet - <skeet@pobox.co m>
        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
        If replying to the group, please do not mail me too

        Comment

        Working...