Interfaces, Big Deal!!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Franco Gustavo

    Interfaces, Big Deal!!

    Hi,



    Please help me to understand this, because I don't see what I'm missing.



    I was reading a lot of examples on Internet that explain that C# doesn't
    implement multiple inheritance it implement multiple interfaces.



    So, I keep reading and reading and reading to see how can I resolve my
    problem with interfaces.

    The conclusion is I'm writing to all of you because I couldn't find the way
    to resolve my problem.



    If I can create multiples interfaces and I have to implement the methods on
    the derived class, then what's the big deal.



    I know if I declare a class that inherit from one interface is useful
    because for example

    I can create an Interface called Shape, and 3 Classes called Circle,
    Rectangle, and Line.

    If on my interface I declare my method Draw(); and I implement on each
    derived class then I could do the next.



    IShape s = (IShape) AnyShapeObject;

    s.draw();



    I think is very useful and I used many times. But now the question is what
    is the similitude between Multiple Inheritance and Multiple Interfaces???? I
    don't see too much



    Why on Internet always speak for Multiple Inheritance and Multiple
    Interfaces like they have a relation???



    My Case:



    I have many Windows Control and I'm inherit each one for create my own
    Controls.

    For example I want to add method called getVirtualSize( );



    I create and interface

    IVirtualSize



    It contain

    public getVirtualSize( );



    So, on my derived class I MUST implement my method getVirtualSize and that's
    it.



    Very nice!!!



    Now the real question is, I create a lot of logic on my paint method; this
    logic is exactly the same for all derived classes, why do I have to
    implement this entire logic on each Control???



    With multiple inheritances you just create a class
    ExtendedControl Funcionality and Implement a method OnPaintEx, and really I
    have a nice source code, because my class ExtendedControl Funcionality has
    all the new extended functionality.



    Then how can I do the same with interfaces????



    I don't want to put my piece of code on every derived class, it is a mess
    and very difficult to maintain, I want to centralize my source code and in
    the same time I want to use many methods of the base classes, that means I
    want to use all the protected methods that the controls offer to me because
    OnPaintEx needs those.



    Really, here is only one example, the reality is that is a lot of source
    code that I "should" implement on every Control, I don't want to do that.



    Thanks, the answers will be really appreciated.

    Gustavo.




  • Sherif ElMetainy

    #2
    Re: Interfaces, Big Deal!!

    Hello

    Unlike C++, C# doesn't support multiple implementaion inheritance. But your
    problem can be solved by deriving the class ExtendedControl Funcionality from
    Control and deriving your class from ExtendedControl Funcionality.

    Best regards,

    Sherif


    "Franco Gustavo" <gfranco@inunti us.com> wrote in message
    news:#hz4qCmiDH A.1564@tk2msftn gp13.phx.gbl...[color=blue]
    > Hi,
    >
    >
    >
    > Please help me to understand this, because I don't see what I'm missing.
    >
    >
    >
    > I was reading a lot of examples on Internet that explain that C# doesn't
    > implement multiple inheritance it implement multiple interfaces.
    >
    >
    >
    > So, I keep reading and reading and reading to see how can I resolve my
    > problem with interfaces.
    >
    > The conclusion is I'm writing to all of you because I couldn't find the[/color]
    way[color=blue]
    > to resolve my problem.
    >
    >
    >
    > If I can create multiples interfaces and I have to implement the methods[/color]
    on[color=blue]
    > the derived class, then what's the big deal.
    >
    >
    >
    > I know if I declare a class that inherit from one interface is useful
    > because for example
    >
    > I can create an Interface called Shape, and 3 Classes called Circle,
    > Rectangle, and Line.
    >
    > If on my interface I declare my method Draw(); and I implement on each
    > derived class then I could do the next.
    >
    >
    >
    > IShape s = (IShape) AnyShapeObject;
    >
    > s.draw();
    >
    >
    >
    > I think is very useful and I used many times. But now the question is what
    > is the similitude between Multiple Inheritance and Multiple Interfaces????[/color]
    I[color=blue]
    > don't see too much
    >
    >
    >
    > Why on Internet always speak for Multiple Inheritance and Multiple
    > Interfaces like they have a relation???
    >
    >
    >
    > My Case:
    >
    >
    >
    > I have many Windows Control and I'm inherit each one for create my own
    > Controls.
    >
    > For example I want to add method called getVirtualSize( );
    >
    >
    >
    > I create and interface
    >
    > IVirtualSize
    >
    >
    >
    > It contain
    >
    > public getVirtualSize( );
    >
    >
    >
    > So, on my derived class I MUST implement my method getVirtualSize and[/color]
    that's[color=blue]
    > it.
    >
    >
    >
    > Very nice!!!
    >
    >
    >
    > Now the real question is, I create a lot of logic on my paint method; this
    > logic is exactly the same for all derived classes, why do I have to
    > implement this entire logic on each Control???
    >
    >
    >
    > With multiple inheritances you just create a class
    > ExtendedControl Funcionality and Implement a method OnPaintEx, and really I
    > have a nice source code, because my class ExtendedControl Funcionality has
    > all the new extended functionality.
    >
    >
    >
    > Then how can I do the same with interfaces????
    >
    >
    >
    > I don't want to put my piece of code on every derived class, it is a mess
    > and very difficult to maintain, I want to centralize my source code and in
    > the same time I want to use many methods of the base classes, that means I
    > want to use all the protected methods that the controls offer to me[/color]
    because[color=blue]
    > OnPaintEx needs those.
    >
    >
    >
    > Really, here is only one example, the reality is that is a lot of source
    > code that I "should" implement on every Control, I don't want to do that.
    >
    >
    >
    > Thanks, the answers will be really appreciated.
    >
    > Gustavo.
    >
    >
    >
    >[/color]


    Comment

    • Sherif ElMetainy

      #3
      Re: Interfaces, Big Deal!!

      Hello

      Unlike C++, C# doesn't support multiple implementaion inheritance. But your
      problem can be solved by deriving the class ExtendedControl Funcionality from
      Control and deriving your class from ExtendedControl Funcionality.

      Best regards,

      Sherif


      "Franco Gustavo" <gfranco@inunti us.com> wrote in message
      news:#hz4qCmiDH A.1564@tk2msftn gp13.phx.gbl...[color=blue]
      > Hi,
      >
      >
      >
      > Please help me to understand this, because I don't see what I'm missing.
      >
      >
      >
      > I was reading a lot of examples on Internet that explain that C# doesn't
      > implement multiple inheritance it implement multiple interfaces.
      >
      >
      >
      > So, I keep reading and reading and reading to see how can I resolve my
      > problem with interfaces.
      >
      > The conclusion is I'm writing to all of you because I couldn't find the[/color]
      way[color=blue]
      > to resolve my problem.
      >
      >
      >
      > If I can create multiples interfaces and I have to implement the methods[/color]
      on[color=blue]
      > the derived class, then what's the big deal.
      >
      >
      >
      > I know if I declare a class that inherit from one interface is useful
      > because for example
      >
      > I can create an Interface called Shape, and 3 Classes called Circle,
      > Rectangle, and Line.
      >
      > If on my interface I declare my method Draw(); and I implement on each
      > derived class then I could do the next.
      >
      >
      >
      > IShape s = (IShape) AnyShapeObject;
      >
      > s.draw();
      >
      >
      >
      > I think is very useful and I used many times. But now the question is what
      > is the similitude between Multiple Inheritance and Multiple Interfaces????[/color]
      I[color=blue]
      > don't see too much
      >
      >
      >
      > Why on Internet always speak for Multiple Inheritance and Multiple
      > Interfaces like they have a relation???
      >
      >
      >
      > My Case:
      >
      >
      >
      > I have many Windows Control and I'm inherit each one for create my own
      > Controls.
      >
      > For example I want to add method called getVirtualSize( );
      >
      >
      >
      > I create and interface
      >
      > IVirtualSize
      >
      >
      >
      > It contain
      >
      > public getVirtualSize( );
      >
      >
      >
      > So, on my derived class I MUST implement my method getVirtualSize and[/color]
      that's[color=blue]
      > it.
      >
      >
      >
      > Very nice!!!
      >
      >
      >
      > Now the real question is, I create a lot of logic on my paint method; this
      > logic is exactly the same for all derived classes, why do I have to
      > implement this entire logic on each Control???
      >
      >
      >
      > With multiple inheritances you just create a class
      > ExtendedControl Funcionality and Implement a method OnPaintEx, and really I
      > have a nice source code, because my class ExtendedControl Funcionality has
      > all the new extended functionality.
      >
      >
      >
      > Then how can I do the same with interfaces????
      >
      >
      >
      > I don't want to put my piece of code on every derived class, it is a mess
      > and very difficult to maintain, I want to centralize my source code and in
      > the same time I want to use many methods of the base classes, that means I
      > want to use all the protected methods that the controls offer to me[/color]
      because[color=blue]
      > OnPaintEx needs those.
      >
      >
      >
      > Really, here is only one example, the reality is that is a lot of source
      > code that I "should" implement on every Control, I don't want to do that.
      >
      >
      >
      > Thanks, the answers will be really appreciated.
      >
      > Gustavo.
      >
      >
      >
      >[/color]


      Comment

      • Franco Gustavo

        #4
        Re: Interfaces, Big Deal!!

        But Control doesn't do anything that I want.

        Basically, I want derive from Label, Panel, GroupBox, CheckBox, RadioButton,
        etc. and add my extended funcionalities

        The Class control doesn't have any funcionality.

        On that case if I derived from Control I have to rewrite each windows
        control from scratch wich is "not possible", doesn't make sense.

        Thanks,
        Gustavo.

        "Sherif ElMetainy" <elmeteny.NOSPA M@wayout.net.NO SPAM> wrote in message
        news:%23yrvKOmi DHA.1048@TK2MSF TNGP11.phx.gbl. ..[color=blue]
        > Hello
        >
        > Unlike C++, C# doesn't support multiple implementaion inheritance. But[/color]
        your[color=blue]
        > problem can be solved by deriving the class ExtendedControl Funcionality[/color]
        from[color=blue]
        > Control and deriving your class from ExtendedControl Funcionality.
        >
        > Best regards,
        >
        > Sherif
        >
        >
        > "Franco Gustavo" <gfranco@inunti us.com> wrote in message
        > news:#hz4qCmiDH A.1564@tk2msftn gp13.phx.gbl...[color=green]
        > > Hi,
        > >
        > >
        > >
        > > Please help me to understand this, because I don't see what I'm missing.
        > >
        > >
        > >
        > > I was reading a lot of examples on Internet that explain that C# doesn't
        > > implement multiple inheritance it implement multiple interfaces.
        > >
        > >
        > >
        > > So, I keep reading and reading and reading to see how can I resolve my
        > > problem with interfaces.
        > >
        > > The conclusion is I'm writing to all of you because I couldn't find the[/color]
        > way[color=green]
        > > to resolve my problem.
        > >
        > >
        > >
        > > If I can create multiples interfaces and I have to implement the methods[/color]
        > on[color=green]
        > > the derived class, then what's the big deal.
        > >
        > >
        > >
        > > I know if I declare a class that inherit from one interface is useful
        > > because for example
        > >
        > > I can create an Interface called Shape, and 3 Classes called Circle,
        > > Rectangle, and Line.
        > >
        > > If on my interface I declare my method Draw(); and I implement on each
        > > derived class then I could do the next.
        > >
        > >
        > >
        > > IShape s = (IShape) AnyShapeObject;
        > >
        > > s.draw();
        > >
        > >
        > >
        > > I think is very useful and I used many times. But now the question is[/color][/color]
        what[color=blue][color=green]
        > > is the similitude between Multiple Inheritance and Multiple[/color][/color]
        Interfaces????[color=blue]
        > I[color=green]
        > > don't see too much
        > >
        > >
        > >
        > > Why on Internet always speak for Multiple Inheritance and Multiple
        > > Interfaces like they have a relation???
        > >
        > >
        > >
        > > My Case:
        > >
        > >
        > >
        > > I have many Windows Control and I'm inherit each one for create my own
        > > Controls.
        > >
        > > For example I want to add method called getVirtualSize( );
        > >
        > >
        > >
        > > I create and interface
        > >
        > > IVirtualSize
        > >
        > >
        > >
        > > It contain
        > >
        > > public getVirtualSize( );
        > >
        > >
        > >
        > > So, on my derived class I MUST implement my method getVirtualSize and[/color]
        > that's[color=green]
        > > it.
        > >
        > >
        > >
        > > Very nice!!!
        > >
        > >
        > >
        > > Now the real question is, I create a lot of logic on my paint method;[/color][/color]
        this[color=blue][color=green]
        > > logic is exactly the same for all derived classes, why do I have to
        > > implement this entire logic on each Control???
        > >
        > >
        > >
        > > With multiple inheritances you just create a class
        > > ExtendedControl Funcionality and Implement a method OnPaintEx, and really[/color][/color]
        I[color=blue][color=green]
        > > have a nice source code, because my class ExtendedControl Funcionality[/color][/color]
        has[color=blue][color=green]
        > > all the new extended functionality.
        > >
        > >
        > >
        > > Then how can I do the same with interfaces????
        > >
        > >
        > >
        > > I don't want to put my piece of code on every derived class, it is a[/color][/color]
        mess[color=blue][color=green]
        > > and very difficult to maintain, I want to centralize my source code and[/color][/color]
        in[color=blue][color=green]
        > > the same time I want to use many methods of the base classes, that means[/color][/color]
        I[color=blue][color=green]
        > > want to use all the protected methods that the controls offer to me[/color]
        > because[color=green]
        > > OnPaintEx needs those.
        > >
        > >
        > >
        > > Really, here is only one example, the reality is that is a lot of source
        > > code that I "should" implement on every Control, I don't want to do[/color][/color]
        that.[color=blue][color=green]
        > >
        > >
        > >
        > > Thanks, the answers will be really appreciated.
        > >
        > > Gustavo.
        > >
        > >
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Franco Gustavo

          #5
          Re: Interfaces, Big Deal!!

          But Control doesn't do anything that I want.

          Basically, I want derive from Label, Panel, GroupBox, CheckBox, RadioButton,
          etc. and add my extended funcionalities

          The Class control doesn't have any funcionality.

          On that case if I derived from Control I have to rewrite each windows
          control from scratch wich is "not possible", doesn't make sense.

          Thanks,
          Gustavo.

          "Sherif ElMetainy" <elmeteny.NOSPA M@wayout.net.NO SPAM> wrote in message
          news:%23yrvKOmi DHA.1048@TK2MSF TNGP11.phx.gbl. ..[color=blue]
          > Hello
          >
          > Unlike C++, C# doesn't support multiple implementaion inheritance. But[/color]
          your[color=blue]
          > problem can be solved by deriving the class ExtendedControl Funcionality[/color]
          from[color=blue]
          > Control and deriving your class from ExtendedControl Funcionality.
          >
          > Best regards,
          >
          > Sherif
          >
          >
          > "Franco Gustavo" <gfranco@inunti us.com> wrote in message
          > news:#hz4qCmiDH A.1564@tk2msftn gp13.phx.gbl...[color=green]
          > > Hi,
          > >
          > >
          > >
          > > Please help me to understand this, because I don't see what I'm missing.
          > >
          > >
          > >
          > > I was reading a lot of examples on Internet that explain that C# doesn't
          > > implement multiple inheritance it implement multiple interfaces.
          > >
          > >
          > >
          > > So, I keep reading and reading and reading to see how can I resolve my
          > > problem with interfaces.
          > >
          > > The conclusion is I'm writing to all of you because I couldn't find the[/color]
          > way[color=green]
          > > to resolve my problem.
          > >
          > >
          > >
          > > If I can create multiples interfaces and I have to implement the methods[/color]
          > on[color=green]
          > > the derived class, then what's the big deal.
          > >
          > >
          > >
          > > I know if I declare a class that inherit from one interface is useful
          > > because for example
          > >
          > > I can create an Interface called Shape, and 3 Classes called Circle,
          > > Rectangle, and Line.
          > >
          > > If on my interface I declare my method Draw(); and I implement on each
          > > derived class then I could do the next.
          > >
          > >
          > >
          > > IShape s = (IShape) AnyShapeObject;
          > >
          > > s.draw();
          > >
          > >
          > >
          > > I think is very useful and I used many times. But now the question is[/color][/color]
          what[color=blue][color=green]
          > > is the similitude between Multiple Inheritance and Multiple[/color][/color]
          Interfaces????[color=blue]
          > I[color=green]
          > > don't see too much
          > >
          > >
          > >
          > > Why on Internet always speak for Multiple Inheritance and Multiple
          > > Interfaces like they have a relation???
          > >
          > >
          > >
          > > My Case:
          > >
          > >
          > >
          > > I have many Windows Control and I'm inherit each one for create my own
          > > Controls.
          > >
          > > For example I want to add method called getVirtualSize( );
          > >
          > >
          > >
          > > I create and interface
          > >
          > > IVirtualSize
          > >
          > >
          > >
          > > It contain
          > >
          > > public getVirtualSize( );
          > >
          > >
          > >
          > > So, on my derived class I MUST implement my method getVirtualSize and[/color]
          > that's[color=green]
          > > it.
          > >
          > >
          > >
          > > Very nice!!!
          > >
          > >
          > >
          > > Now the real question is, I create a lot of logic on my paint method;[/color][/color]
          this[color=blue][color=green]
          > > logic is exactly the same for all derived classes, why do I have to
          > > implement this entire logic on each Control???
          > >
          > >
          > >
          > > With multiple inheritances you just create a class
          > > ExtendedControl Funcionality and Implement a method OnPaintEx, and really[/color][/color]
          I[color=blue][color=green]
          > > have a nice source code, because my class ExtendedControl Funcionality[/color][/color]
          has[color=blue][color=green]
          > > all the new extended functionality.
          > >
          > >
          > >
          > > Then how can I do the same with interfaces????
          > >
          > >
          > >
          > > I don't want to put my piece of code on every derived class, it is a[/color][/color]
          mess[color=blue][color=green]
          > > and very difficult to maintain, I want to centralize my source code and[/color][/color]
          in[color=blue][color=green]
          > > the same time I want to use many methods of the base classes, that means[/color][/color]
          I[color=blue][color=green]
          > > want to use all the protected methods that the controls offer to me[/color]
          > because[color=green]
          > > OnPaintEx needs those.
          > >
          > >
          > >
          > > Really, here is only one example, the reality is that is a lot of source
          > > code that I "should" implement on every Control, I don't want to do[/color][/color]
          that.[color=blue][color=green]
          > >
          > >
          > >
          > > Thanks, the answers will be really appreciated.
          > >
          > > Gustavo.
          > >
          > >
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Kieran Benton

            #6
            Re: Interfaces, Big Deal!!

            So just have a class that has private members of all those types. Inheriting
            from all of the GUI classes does not make sense as they are all functionally
            different.

            Kieran

            "Franco Gustavo" <gfranco@inunti us.com> wrote in message
            news:uSkgoXmiDH A.3660@tk2msftn gp13.phx.gbl...[color=blue]
            > But Control doesn't do anything that I want.
            >
            > Basically, I want derive from Label, Panel, GroupBox, CheckBox,[/color]
            RadioButton,[color=blue]
            > etc. and add my extended funcionalities
            >
            > The Class control doesn't have any funcionality.
            >
            > On that case if I derived from Control I have to rewrite each windows
            > control from scratch wich is "not possible", doesn't make sense.
            >
            > Thanks,
            > Gustavo.
            >
            > "Sherif ElMetainy" <elmeteny.NOSPA M@wayout.net.NO SPAM> wrote in message
            > news:%23yrvKOmi DHA.1048@TK2MSF TNGP11.phx.gbl. ..[color=green]
            > > Hello
            > >
            > > Unlike C++, C# doesn't support multiple implementaion inheritance. But[/color]
            > your[color=green]
            > > problem can be solved by deriving the class ExtendedControl Funcionality[/color]
            > from[color=green]
            > > Control and deriving your class from ExtendedControl Funcionality.
            > >
            > > Best regards,
            > >
            > > Sherif
            > >
            > >
            > > "Franco Gustavo" <gfranco@inunti us.com> wrote in message
            > > news:#hz4qCmiDH A.1564@tk2msftn gp13.phx.gbl...[color=darkred]
            > > > Hi,
            > > >
            > > >
            > > >
            > > > Please help me to understand this, because I don't see what I'm[/color][/color][/color]
            missing.[color=blue][color=green][color=darkred]
            > > >
            > > >
            > > >
            > > > I was reading a lot of examples on Internet that explain that C#[/color][/color][/color]
            doesn't[color=blue][color=green][color=darkred]
            > > > implement multiple inheritance it implement multiple interfaces.
            > > >
            > > >
            > > >
            > > > So, I keep reading and reading and reading to see how can I resolve my
            > > > problem with interfaces.
            > > >
            > > > The conclusion is I'm writing to all of you because I couldn't find[/color][/color][/color]
            the[color=blue][color=green]
            > > way[color=darkred]
            > > > to resolve my problem.
            > > >
            > > >
            > > >
            > > > If I can create multiples interfaces and I have to implement the[/color][/color][/color]
            methods[color=blue][color=green]
            > > on[color=darkred]
            > > > the derived class, then what's the big deal.
            > > >
            > > >
            > > >
            > > > I know if I declare a class that inherit from one interface is useful
            > > > because for example
            > > >
            > > > I can create an Interface called Shape, and 3 Classes called Circle,
            > > > Rectangle, and Line.
            > > >
            > > > If on my interface I declare my method Draw(); and I implement on each
            > > > derived class then I could do the next.
            > > >
            > > >
            > > >
            > > > IShape s = (IShape) AnyShapeObject;
            > > >
            > > > s.draw();
            > > >
            > > >
            > > >
            > > > I think is very useful and I used many times. But now the question is[/color][/color]
            > what[color=green][color=darkred]
            > > > is the similitude between Multiple Inheritance and Multiple[/color][/color]
            > Interfaces????[color=green]
            > > I[color=darkred]
            > > > don't see too much
            > > >
            > > >
            > > >
            > > > Why on Internet always speak for Multiple Inheritance and Multiple
            > > > Interfaces like they have a relation???
            > > >
            > > >
            > > >
            > > > My Case:
            > > >
            > > >
            > > >
            > > > I have many Windows Control and I'm inherit each one for create my own
            > > > Controls.
            > > >
            > > > For example I want to add method called getVirtualSize( );
            > > >
            > > >
            > > >
            > > > I create and interface
            > > >
            > > > IVirtualSize
            > > >
            > > >
            > > >
            > > > It contain
            > > >
            > > > public getVirtualSize( );
            > > >
            > > >
            > > >
            > > > So, on my derived class I MUST implement my method getVirtualSize and[/color]
            > > that's[color=darkred]
            > > > it.
            > > >
            > > >
            > > >
            > > > Very nice!!!
            > > >
            > > >
            > > >
            > > > Now the real question is, I create a lot of logic on my paint method;[/color][/color]
            > this[color=green][color=darkred]
            > > > logic is exactly the same for all derived classes, why do I have to
            > > > implement this entire logic on each Control???
            > > >
            > > >
            > > >
            > > > With multiple inheritances you just create a class
            > > > ExtendedControl Funcionality and Implement a method OnPaintEx, and[/color][/color][/color]
            really[color=blue]
            > I[color=green][color=darkred]
            > > > have a nice source code, because my class ExtendedControl Funcionality[/color][/color]
            > has[color=green][color=darkred]
            > > > all the new extended functionality.
            > > >
            > > >
            > > >
            > > > Then how can I do the same with interfaces????
            > > >
            > > >
            > > >
            > > > I don't want to put my piece of code on every derived class, it is a[/color][/color]
            > mess[color=green][color=darkred]
            > > > and very difficult to maintain, I want to centralize my source code[/color][/color][/color]
            and[color=blue]
            > in[color=green][color=darkred]
            > > > the same time I want to use many methods of the base classes, that[/color][/color][/color]
            means[color=blue]
            > I[color=green][color=darkred]
            > > > want to use all the protected methods that the controls offer to me[/color]
            > > because[color=darkred]
            > > > OnPaintEx needs those.
            > > >
            > > >
            > > >
            > > > Really, here is only one example, the reality is that is a lot of[/color][/color][/color]
            source[color=blue][color=green][color=darkred]
            > > > code that I "should" implement on every Control, I don't want to do[/color][/color]
            > that.[color=green][color=darkred]
            > > >
            > > >
            > > >
            > > > Thanks, the answers will be really appreciated.
            > > >
            > > > Gustavo.
            > > >
            > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Kieran Benton

              #7
              Re: Interfaces, Big Deal!!

              So just have a class that has private members of all those types. Inheriting
              from all of the GUI classes does not make sense as they are all functionally
              different.

              Kieran

              "Franco Gustavo" <gfranco@inunti us.com> wrote in message
              news:uSkgoXmiDH A.3660@tk2msftn gp13.phx.gbl...[color=blue]
              > But Control doesn't do anything that I want.
              >
              > Basically, I want derive from Label, Panel, GroupBox, CheckBox,[/color]
              RadioButton,[color=blue]
              > etc. and add my extended funcionalities
              >
              > The Class control doesn't have any funcionality.
              >
              > On that case if I derived from Control I have to rewrite each windows
              > control from scratch wich is "not possible", doesn't make sense.
              >
              > Thanks,
              > Gustavo.
              >
              > "Sherif ElMetainy" <elmeteny.NOSPA M@wayout.net.NO SPAM> wrote in message
              > news:%23yrvKOmi DHA.1048@TK2MSF TNGP11.phx.gbl. ..[color=green]
              > > Hello
              > >
              > > Unlike C++, C# doesn't support multiple implementaion inheritance. But[/color]
              > your[color=green]
              > > problem can be solved by deriving the class ExtendedControl Funcionality[/color]
              > from[color=green]
              > > Control and deriving your class from ExtendedControl Funcionality.
              > >
              > > Best regards,
              > >
              > > Sherif
              > >
              > >
              > > "Franco Gustavo" <gfranco@inunti us.com> wrote in message
              > > news:#hz4qCmiDH A.1564@tk2msftn gp13.phx.gbl...[color=darkred]
              > > > Hi,
              > > >
              > > >
              > > >
              > > > Please help me to understand this, because I don't see what I'm[/color][/color][/color]
              missing.[color=blue][color=green][color=darkred]
              > > >
              > > >
              > > >
              > > > I was reading a lot of examples on Internet that explain that C#[/color][/color][/color]
              doesn't[color=blue][color=green][color=darkred]
              > > > implement multiple inheritance it implement multiple interfaces.
              > > >
              > > >
              > > >
              > > > So, I keep reading and reading and reading to see how can I resolve my
              > > > problem with interfaces.
              > > >
              > > > The conclusion is I'm writing to all of you because I couldn't find[/color][/color][/color]
              the[color=blue][color=green]
              > > way[color=darkred]
              > > > to resolve my problem.
              > > >
              > > >
              > > >
              > > > If I can create multiples interfaces and I have to implement the[/color][/color][/color]
              methods[color=blue][color=green]
              > > on[color=darkred]
              > > > the derived class, then what's the big deal.
              > > >
              > > >
              > > >
              > > > I know if I declare a class that inherit from one interface is useful
              > > > because for example
              > > >
              > > > I can create an Interface called Shape, and 3 Classes called Circle,
              > > > Rectangle, and Line.
              > > >
              > > > If on my interface I declare my method Draw(); and I implement on each
              > > > derived class then I could do the next.
              > > >
              > > >
              > > >
              > > > IShape s = (IShape) AnyShapeObject;
              > > >
              > > > s.draw();
              > > >
              > > >
              > > >
              > > > I think is very useful and I used many times. But now the question is[/color][/color]
              > what[color=green][color=darkred]
              > > > is the similitude between Multiple Inheritance and Multiple[/color][/color]
              > Interfaces????[color=green]
              > > I[color=darkred]
              > > > don't see too much
              > > >
              > > >
              > > >
              > > > Why on Internet always speak for Multiple Inheritance and Multiple
              > > > Interfaces like they have a relation???
              > > >
              > > >
              > > >
              > > > My Case:
              > > >
              > > >
              > > >
              > > > I have many Windows Control and I'm inherit each one for create my own
              > > > Controls.
              > > >
              > > > For example I want to add method called getVirtualSize( );
              > > >
              > > >
              > > >
              > > > I create and interface
              > > >
              > > > IVirtualSize
              > > >
              > > >
              > > >
              > > > It contain
              > > >
              > > > public getVirtualSize( );
              > > >
              > > >
              > > >
              > > > So, on my derived class I MUST implement my method getVirtualSize and[/color]
              > > that's[color=darkred]
              > > > it.
              > > >
              > > >
              > > >
              > > > Very nice!!!
              > > >
              > > >
              > > >
              > > > Now the real question is, I create a lot of logic on my paint method;[/color][/color]
              > this[color=green][color=darkred]
              > > > logic is exactly the same for all derived classes, why do I have to
              > > > implement this entire logic on each Control???
              > > >
              > > >
              > > >
              > > > With multiple inheritances you just create a class
              > > > ExtendedControl Funcionality and Implement a method OnPaintEx, and[/color][/color][/color]
              really[color=blue]
              > I[color=green][color=darkred]
              > > > have a nice source code, because my class ExtendedControl Funcionality[/color][/color]
              > has[color=green][color=darkred]
              > > > all the new extended functionality.
              > > >
              > > >
              > > >
              > > > Then how can I do the same with interfaces????
              > > >
              > > >
              > > >
              > > > I don't want to put my piece of code on every derived class, it is a[/color][/color]
              > mess[color=green][color=darkred]
              > > > and very difficult to maintain, I want to centralize my source code[/color][/color][/color]
              and[color=blue]
              > in[color=green][color=darkred]
              > > > the same time I want to use many methods of the base classes, that[/color][/color][/color]
              means[color=blue]
              > I[color=green][color=darkred]
              > > > want to use all the protected methods that the controls offer to me[/color]
              > > because[color=darkred]
              > > > OnPaintEx needs those.
              > > >
              > > >
              > > >
              > > > Really, here is only one example, the reality is that is a lot of[/color][/color][/color]
              source[color=blue][color=green][color=darkred]
              > > > code that I "should" implement on every Control, I don't want to do[/color][/color]
              > that.[color=green][color=darkred]
              > > >
              > > >
              > > >
              > > > Thanks, the answers will be really appreciated.
              > > >
              > > > Gustavo.
              > > >
              > > >
              > > >
              > > >[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Anon

                #8
                Re: Interfaces, Big Deal!!

                Can you implement the logic into a function (if VB) or static method in a
                class (VB or C#). Then for a control, implement your new interface and in
                the method of the implemented interface just pass the call onto the function
                or shared method?



                "Franco Gustavo" <gfranco@inunti us.com> wrote in message
                news:uSkgoXmiDH A.3660@tk2msftn gp13.phx.gbl...[color=blue]
                > But Control doesn't do anything that I want.
                >
                > Basically, I want derive from Label, Panel, GroupBox, CheckBox,[/color]
                RadioButton,[color=blue]
                > etc. and add my extended funcionalities
                >
                > The Class control doesn't have any funcionality.
                >
                > On that case if I derived from Control I have to rewrite each windows
                > control from scratch wich is "not possible", doesn't make sense.
                >
                > Thanks,
                > Gustavo.
                >
                > "Sherif ElMetainy" <elmeteny.NOSPA M@wayout.net.NO SPAM> wrote in message
                > news:%23yrvKOmi DHA.1048@TK2MSF TNGP11.phx.gbl. ..[color=green]
                > > Hello
                > >
                > > Unlike C++, C# doesn't support multiple implementaion inheritance. But[/color]
                > your[color=green]
                > > problem can be solved by deriving the class ExtendedControl Funcionality[/color]
                > from[color=green]
                > > Control and deriving your class from ExtendedControl Funcionality.
                > >
                > > Best regards,
                > >
                > > Sherif
                > >
                > >
                > > "Franco Gustavo" <gfranco@inunti us.com> wrote in message
                > > news:#hz4qCmiDH A.1564@tk2msftn gp13.phx.gbl...[color=darkred]
                > > > Hi,
                > > >
                > > >
                > > >
                > > > Please help me to understand this, because I don't see what I'm[/color][/color][/color]
                missing.[color=blue][color=green][color=darkred]
                > > >
                > > >
                > > >
                > > > I was reading a lot of examples on Internet that explain that C#[/color][/color][/color]
                doesn't[color=blue][color=green][color=darkred]
                > > > implement multiple inheritance it implement multiple interfaces.
                > > >
                > > >
                > > >
                > > > So, I keep reading and reading and reading to see how can I resolve my
                > > > problem with interfaces.
                > > >
                > > > The conclusion is I'm writing to all of you because I couldn't find[/color][/color][/color]
                the[color=blue][color=green]
                > > way[color=darkred]
                > > > to resolve my problem.
                > > >
                > > >
                > > >
                > > > If I can create multiples interfaces and I have to implement the[/color][/color][/color]
                methods[color=blue][color=green]
                > > on[color=darkred]
                > > > the derived class, then what's the big deal.
                > > >
                > > >
                > > >
                > > > I know if I declare a class that inherit from one interface is useful
                > > > because for example
                > > >
                > > > I can create an Interface called Shape, and 3 Classes called Circle,
                > > > Rectangle, and Line.
                > > >
                > > > If on my interface I declare my method Draw(); and I implement on each
                > > > derived class then I could do the next.
                > > >
                > > >
                > > >
                > > > IShape s = (IShape) AnyShapeObject;
                > > >
                > > > s.draw();
                > > >
                > > >
                > > >
                > > > I think is very useful and I used many times. But now the question is[/color][/color]
                > what[color=green][color=darkred]
                > > > is the similitude between Multiple Inheritance and Multiple[/color][/color]
                > Interfaces????[color=green]
                > > I[color=darkred]
                > > > don't see too much
                > > >
                > > >
                > > >
                > > > Why on Internet always speak for Multiple Inheritance and Multiple
                > > > Interfaces like they have a relation???
                > > >
                > > >
                > > >
                > > > My Case:
                > > >
                > > >
                > > >
                > > > I have many Windows Control and I'm inherit each one for create my own
                > > > Controls.
                > > >
                > > > For example I want to add method called getVirtualSize( );
                > > >
                > > >
                > > >
                > > > I create and interface
                > > >
                > > > IVirtualSize
                > > >
                > > >
                > > >
                > > > It contain
                > > >
                > > > public getVirtualSize( );
                > > >
                > > >
                > > >
                > > > So, on my derived class I MUST implement my method getVirtualSize and[/color]
                > > that's[color=darkred]
                > > > it.
                > > >
                > > >
                > > >
                > > > Very nice!!!
                > > >
                > > >
                > > >
                > > > Now the real question is, I create a lot of logic on my paint method;[/color][/color]
                > this[color=green][color=darkred]
                > > > logic is exactly the same for all derived classes, why do I have to
                > > > implement this entire logic on each Control???
                > > >
                > > >
                > > >
                > > > With multiple inheritances you just create a class
                > > > ExtendedControl Funcionality and Implement a method OnPaintEx, and[/color][/color][/color]
                really[color=blue]
                > I[color=green][color=darkred]
                > > > have a nice source code, because my class ExtendedControl Funcionality[/color][/color]
                > has[color=green][color=darkred]
                > > > all the new extended functionality.
                > > >
                > > >
                > > >
                > > > Then how can I do the same with interfaces????
                > > >
                > > >
                > > >
                > > > I don't want to put my piece of code on every derived class, it is a[/color][/color]
                > mess[color=green][color=darkred]
                > > > and very difficult to maintain, I want to centralize my source code[/color][/color][/color]
                and[color=blue]
                > in[color=green][color=darkred]
                > > > the same time I want to use many methods of the base classes, that[/color][/color][/color]
                means[color=blue]
                > I[color=green][color=darkred]
                > > > want to use all the protected methods that the controls offer to me[/color]
                > > because[color=darkred]
                > > > OnPaintEx needs those.
                > > >
                > > >
                > > >
                > > > Really, here is only one example, the reality is that is a lot of[/color][/color][/color]
                source[color=blue][color=green][color=darkred]
                > > > code that I "should" implement on every Control, I don't want to do[/color][/color]
                > that.[color=green][color=darkred]
                > > >
                > > >
                > > >
                > > > Thanks, the answers will be really appreciated.
                > > >
                > > > Gustavo.
                > > >
                > > >
                > > >
                > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • Anon

                  #9
                  Re: Interfaces, Big Deal!!

                  Can you implement the logic into a function (if VB) or static method in a
                  class (VB or C#). Then for a control, implement your new interface and in
                  the method of the implemented interface just pass the call onto the function
                  or shared method?



                  "Franco Gustavo" <gfranco@inunti us.com> wrote in message
                  news:uSkgoXmiDH A.3660@tk2msftn gp13.phx.gbl...[color=blue]
                  > But Control doesn't do anything that I want.
                  >
                  > Basically, I want derive from Label, Panel, GroupBox, CheckBox,[/color]
                  RadioButton,[color=blue]
                  > etc. and add my extended funcionalities
                  >
                  > The Class control doesn't have any funcionality.
                  >
                  > On that case if I derived from Control I have to rewrite each windows
                  > control from scratch wich is "not possible", doesn't make sense.
                  >
                  > Thanks,
                  > Gustavo.
                  >
                  > "Sherif ElMetainy" <elmeteny.NOSPA M@wayout.net.NO SPAM> wrote in message
                  > news:%23yrvKOmi DHA.1048@TK2MSF TNGP11.phx.gbl. ..[color=green]
                  > > Hello
                  > >
                  > > Unlike C++, C# doesn't support multiple implementaion inheritance. But[/color]
                  > your[color=green]
                  > > problem can be solved by deriving the class ExtendedControl Funcionality[/color]
                  > from[color=green]
                  > > Control and deriving your class from ExtendedControl Funcionality.
                  > >
                  > > Best regards,
                  > >
                  > > Sherif
                  > >
                  > >
                  > > "Franco Gustavo" <gfranco@inunti us.com> wrote in message
                  > > news:#hz4qCmiDH A.1564@tk2msftn gp13.phx.gbl...[color=darkred]
                  > > > Hi,
                  > > >
                  > > >
                  > > >
                  > > > Please help me to understand this, because I don't see what I'm[/color][/color][/color]
                  missing.[color=blue][color=green][color=darkred]
                  > > >
                  > > >
                  > > >
                  > > > I was reading a lot of examples on Internet that explain that C#[/color][/color][/color]
                  doesn't[color=blue][color=green][color=darkred]
                  > > > implement multiple inheritance it implement multiple interfaces.
                  > > >
                  > > >
                  > > >
                  > > > So, I keep reading and reading and reading to see how can I resolve my
                  > > > problem with interfaces.
                  > > >
                  > > > The conclusion is I'm writing to all of you because I couldn't find[/color][/color][/color]
                  the[color=blue][color=green]
                  > > way[color=darkred]
                  > > > to resolve my problem.
                  > > >
                  > > >
                  > > >
                  > > > If I can create multiples interfaces and I have to implement the[/color][/color][/color]
                  methods[color=blue][color=green]
                  > > on[color=darkred]
                  > > > the derived class, then what's the big deal.
                  > > >
                  > > >
                  > > >
                  > > > I know if I declare a class that inherit from one interface is useful
                  > > > because for example
                  > > >
                  > > > I can create an Interface called Shape, and 3 Classes called Circle,
                  > > > Rectangle, and Line.
                  > > >
                  > > > If on my interface I declare my method Draw(); and I implement on each
                  > > > derived class then I could do the next.
                  > > >
                  > > >
                  > > >
                  > > > IShape s = (IShape) AnyShapeObject;
                  > > >
                  > > > s.draw();
                  > > >
                  > > >
                  > > >
                  > > > I think is very useful and I used many times. But now the question is[/color][/color]
                  > what[color=green][color=darkred]
                  > > > is the similitude between Multiple Inheritance and Multiple[/color][/color]
                  > Interfaces????[color=green]
                  > > I[color=darkred]
                  > > > don't see too much
                  > > >
                  > > >
                  > > >
                  > > > Why on Internet always speak for Multiple Inheritance and Multiple
                  > > > Interfaces like they have a relation???
                  > > >
                  > > >
                  > > >
                  > > > My Case:
                  > > >
                  > > >
                  > > >
                  > > > I have many Windows Control and I'm inherit each one for create my own
                  > > > Controls.
                  > > >
                  > > > For example I want to add method called getVirtualSize( );
                  > > >
                  > > >
                  > > >
                  > > > I create and interface
                  > > >
                  > > > IVirtualSize
                  > > >
                  > > >
                  > > >
                  > > > It contain
                  > > >
                  > > > public getVirtualSize( );
                  > > >
                  > > >
                  > > >
                  > > > So, on my derived class I MUST implement my method getVirtualSize and[/color]
                  > > that's[color=darkred]
                  > > > it.
                  > > >
                  > > >
                  > > >
                  > > > Very nice!!!
                  > > >
                  > > >
                  > > >
                  > > > Now the real question is, I create a lot of logic on my paint method;[/color][/color]
                  > this[color=green][color=darkred]
                  > > > logic is exactly the same for all derived classes, why do I have to
                  > > > implement this entire logic on each Control???
                  > > >
                  > > >
                  > > >
                  > > > With multiple inheritances you just create a class
                  > > > ExtendedControl Funcionality and Implement a method OnPaintEx, and[/color][/color][/color]
                  really[color=blue]
                  > I[color=green][color=darkred]
                  > > > have a nice source code, because my class ExtendedControl Funcionality[/color][/color]
                  > has[color=green][color=darkred]
                  > > > all the new extended functionality.
                  > > >
                  > > >
                  > > >
                  > > > Then how can I do the same with interfaces????
                  > > >
                  > > >
                  > > >
                  > > > I don't want to put my piece of code on every derived class, it is a[/color][/color]
                  > mess[color=green][color=darkred]
                  > > > and very difficult to maintain, I want to centralize my source code[/color][/color][/color]
                  and[color=blue]
                  > in[color=green][color=darkred]
                  > > > the same time I want to use many methods of the base classes, that[/color][/color][/color]
                  means[color=blue]
                  > I[color=green][color=darkred]
                  > > > want to use all the protected methods that the controls offer to me[/color]
                  > > because[color=darkred]
                  > > > OnPaintEx needs those.
                  > > >
                  > > >
                  > > >
                  > > > Really, here is only one example, the reality is that is a lot of[/color][/color][/color]
                  source[color=blue][color=green][color=darkred]
                  > > > code that I "should" implement on every Control, I don't want to do[/color][/color]
                  > that.[color=green][color=darkred]
                  > > >
                  > > >
                  > > >
                  > > > Thanks, the answers will be really appreciated.
                  > > >
                  > > > Gustavo.
                  > > >
                  > > >
                  > > >
                  > > >[/color]
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • Fergus Cooney

                    #10
                    Re: Interfaces, Big Deal!!

                    Hi Kieran,

                    || So just have a class that has private members of all those types.

                    I'm not sure how that would work.

                    || Inheriting from all of the GUI classes does not make sense as
                    || they are all functionally different.

                    That's exactly the point - disparate objects but which require a <common
                    Capability>. Franco would have a FrancoLabel which would inherit from Label
                    and CapCtrlExtensio ns, and a FrancoPanel - Panel and CapCtrlExtensio ns, etc,
                    etc.

                    Using the interface approach means that the code has to be duplicated in
                    each of the ingheriting classes. Using multiple inheritance means bolting the
                    Capability on. Write once, re-use - it's what OOP shouts from the rooftops.

                    Regards,
                    Fergus


                    Comment

                    • Fergus Cooney

                      #11
                      Re: Interfaces, Big Deal!!

                      Hi Kieran,

                      || So just have a class that has private members of all those types.

                      I'm not sure how that would work.

                      || Inheriting from all of the GUI classes does not make sense as
                      || they are all functionally different.

                      That's exactly the point - disparate objects but which require a <common
                      Capability>. Franco would have a FrancoLabel which would inherit from Label
                      and CapCtrlExtensio ns, and a FrancoPanel - Panel and CapCtrlExtensio ns, etc,
                      etc.

                      Using the interface approach means that the code has to be duplicated in
                      each of the ingheriting classes. Using multiple inheritance means bolting the
                      Capability on. Write once, re-use - it's what OOP shouts from the rooftops.

                      Regards,
                      Fergus


                      Comment

                      • Franco Gustavo

                        #12
                        Re: Interfaces, Big Deal!!

                        Yep, I tried that, but if you pass the control to a function on different
                        class (static or not static) then you can't get access to the protected
                        methods from the control.



                        Basically, My application is skinned, and I needed "true" transparent
                        controls.



                        Windows Problem

                        1) On Many controls you can't set Background like transparent,
                        (Color.Transpar ent)

                        2) Controls like GroupBox they capture the background wrong (if you have a
                        gradient background on the parent windows and the GroupBox is on the
                        position 50,50 then the background is capture from the Parent from the
                        position 0,0 which is wrong, because the GroupBox doesn't looks like
                        transparent in at all, has the gradient translated)

                        3) On the Controls that accept Color.Transpare nt, if you have a control on
                        Color.Transpare nt color and there is another control behind it (is not child
                        or parent, they have the same parent), Windows just capture the parent
                        Background which is wrong again, because you can't see the control that is
                        behind him.



                        So, what I did is inherit every control of windows, create my own BackBuffer
                        where I keep all my window status and changes, avoid call to
                        OnPaintBackgrou nd, and I take the process to draw the portion that windows
                        ask me to redraw with my own BackBuffer.



                        So, All this process is standard for every control and work really good,
                        then I can get "true" transparency and you don't see the difference on
                        performance.



                        But the code is ugly, because I have the same method implementation like 10
                        times!!!



                        Then the only that I need is consolidate my functionality on just one single
                        Class, Interface, Method or whatever I need.

                        On C++ if you do multi-inheritance then I can get what I'm looking for.



                        So, there is some way to emulate multi-inheritance on C#?????



                        I though interface was the answer. I see may be interface can't do too much
                        here, then some idea???



                        Thanks,

                        Gustavo.



                        P.S.: I think this is a very commun problem where you have to add
                        funcionality to thirdparty classes where you have to inherit from each one
                        of them and you have to share code for all of them.



                        "Anon" <Anon@Anon.Anon > wrote in message
                        news:7tyfb.2154 35$mp.133809@rw crnsc51.ops.asp .att.net...[color=blue]
                        > Can you implement the logic into a function (if VB) or static method in a
                        > class (VB or C#). Then for a control, implement your new interface and in
                        > the method of the implemented interface just pass the call onto the[/color]
                        function[color=blue]
                        > or shared method?
                        >
                        >
                        >
                        > "Franco Gustavo" <gfranco@inunti us.com> wrote in message
                        > news:uSkgoXmiDH A.3660@tk2msftn gp13.phx.gbl...[color=green]
                        > > But Control doesn't do anything that I want.
                        > >
                        > > Basically, I want derive from Label, Panel, GroupBox, CheckBox,[/color]
                        > RadioButton,[color=green]
                        > > etc. and add my extended funcionalities
                        > >
                        > > The Class control doesn't have any funcionality.
                        > >
                        > > On that case if I derived from Control I have to rewrite each windows
                        > > control from scratch wich is "not possible", doesn't make sense.
                        > >
                        > > Thanks,
                        > > Gustavo.
                        > >
                        > > "Sherif ElMetainy" <elmeteny.NOSPA M@wayout.net.NO SPAM> wrote in message
                        > > news:%23yrvKOmi DHA.1048@TK2MSF TNGP11.phx.gbl. ..[color=darkred]
                        > > > Hello
                        > > >
                        > > > Unlike C++, C# doesn't support multiple implementaion inheritance. But[/color]
                        > > your[color=darkred]
                        > > > problem can be solved by deriving the class[/color][/color][/color]
                        ExtendedControl Funcionality[color=blue][color=green]
                        > > from[color=darkred]
                        > > > Control and deriving your class from ExtendedControl Funcionality.
                        > > >
                        > > > Best regards,
                        > > >
                        > > > Sherif
                        > > >
                        > > >
                        > > > "Franco Gustavo" <gfranco@inunti us.com> wrote in message
                        > > > news:#hz4qCmiDH A.1564@tk2msftn gp13.phx.gbl...
                        > > > > Hi,
                        > > > >
                        > > > >
                        > > > >
                        > > > > Please help me to understand this, because I don't see what I'm[/color][/color]
                        > missing.[color=green][color=darkred]
                        > > > >
                        > > > >
                        > > > >
                        > > > > I was reading a lot of examples on Internet that explain that C#[/color][/color]
                        > doesn't[color=green][color=darkred]
                        > > > > implement multiple inheritance it implement multiple interfaces.
                        > > > >
                        > > > >
                        > > > >
                        > > > > So, I keep reading and reading and reading to see how can I resolve[/color][/color][/color]
                        my[color=blue][color=green][color=darkred]
                        > > > > problem with interfaces.
                        > > > >
                        > > > > The conclusion is I'm writing to all of you because I couldn't find[/color][/color]
                        > the[color=green][color=darkred]
                        > > > way
                        > > > > to resolve my problem.
                        > > > >
                        > > > >
                        > > > >
                        > > > > If I can create multiples interfaces and I have to implement the[/color][/color]
                        > methods[color=green][color=darkred]
                        > > > on
                        > > > > the derived class, then what's the big deal.
                        > > > >
                        > > > >
                        > > > >
                        > > > > I know if I declare a class that inherit from one interface is[/color][/color][/color]
                        useful[color=blue][color=green][color=darkred]
                        > > > > because for example
                        > > > >
                        > > > > I can create an Interface called Shape, and 3 Classes called Circle,
                        > > > > Rectangle, and Line.
                        > > > >
                        > > > > If on my interface I declare my method Draw(); and I implement on[/color][/color][/color]
                        each[color=blue][color=green][color=darkred]
                        > > > > derived class then I could do the next.
                        > > > >
                        > > > >
                        > > > >
                        > > > > IShape s = (IShape) AnyShapeObject;
                        > > > >
                        > > > > s.draw();
                        > > > >
                        > > > >
                        > > > >
                        > > > > I think is very useful and I used many times. But now the question[/color][/color][/color]
                        is[color=blue][color=green]
                        > > what[color=darkred]
                        > > > > is the similitude between Multiple Inheritance and Multiple[/color]
                        > > Interfaces????[color=darkred]
                        > > > I
                        > > > > don't see too much
                        > > > >
                        > > > >
                        > > > >
                        > > > > Why on Internet always speak for Multiple Inheritance and Multiple
                        > > > > Interfaces like they have a relation???
                        > > > >
                        > > > >
                        > > > >
                        > > > > My Case:
                        > > > >
                        > > > >
                        > > > >
                        > > > > I have many Windows Control and I'm inherit each one for create my[/color][/color][/color]
                        own[color=blue][color=green][color=darkred]
                        > > > > Controls.
                        > > > >
                        > > > > For example I want to add method called getVirtualSize( );
                        > > > >
                        > > > >
                        > > > >
                        > > > > I create and interface
                        > > > >
                        > > > > IVirtualSize
                        > > > >
                        > > > >
                        > > > >
                        > > > > It contain
                        > > > >
                        > > > > public getVirtualSize( );
                        > > > >
                        > > > >
                        > > > >
                        > > > > So, on my derived class I MUST implement my method getVirtualSize[/color][/color][/color]
                        and[color=blue][color=green][color=darkred]
                        > > > that's
                        > > > > it.
                        > > > >
                        > > > >
                        > > > >
                        > > > > Very nice!!!
                        > > > >
                        > > > >
                        > > > >
                        > > > > Now the real question is, I create a lot of logic on my paint[/color][/color][/color]
                        method;[color=blue][color=green]
                        > > this[color=darkred]
                        > > > > logic is exactly the same for all derived classes, why do I have to
                        > > > > implement this entire logic on each Control???
                        > > > >
                        > > > >
                        > > > >
                        > > > > With multiple inheritances you just create a class
                        > > > > ExtendedControl Funcionality and Implement a method OnPaintEx, and[/color][/color]
                        > really[color=green]
                        > > I[color=darkred]
                        > > > > have a nice source code, because my class[/color][/color][/color]
                        ExtendedControl Funcionality[color=blue][color=green]
                        > > has[color=darkred]
                        > > > > all the new extended functionality.
                        > > > >
                        > > > >
                        > > > >
                        > > > > Then how can I do the same with interfaces????
                        > > > >
                        > > > >
                        > > > >
                        > > > > I don't want to put my piece of code on every derived class, it is a[/color]
                        > > mess[color=darkred]
                        > > > > and very difficult to maintain, I want to centralize my source code[/color][/color]
                        > and[color=green]
                        > > in[color=darkred]
                        > > > > the same time I want to use many methods of the base classes, that[/color][/color]
                        > means[color=green]
                        > > I[color=darkred]
                        > > > > want to use all the protected methods that the controls offer to me
                        > > > because
                        > > > > OnPaintEx needs those.
                        > > > >
                        > > > >
                        > > > >
                        > > > > Really, here is only one example, the reality is that is a lot of[/color][/color]
                        > source[color=green][color=darkred]
                        > > > > code that I "should" implement on every Control, I don't want to do[/color]
                        > > that.[color=darkred]
                        > > > >
                        > > > >
                        > > > >
                        > > > > Thanks, the answers will be really appreciated.
                        > > > >
                        > > > > Gustavo.
                        > > > >
                        > > > >
                        > > > >
                        > > > >
                        > > >
                        > > >[/color]
                        > >
                        > >[/color]
                        >
                        >[/color]


                        Comment

                        • Franco Gustavo

                          #13
                          Re: Interfaces, Big Deal!!

                          Yep, I tried that, but if you pass the control to a function on different
                          class (static or not static) then you can't get access to the protected
                          methods from the control.



                          Basically, My application is skinned, and I needed "true" transparent
                          controls.



                          Windows Problem

                          1) On Many controls you can't set Background like transparent,
                          (Color.Transpar ent)

                          2) Controls like GroupBox they capture the background wrong (if you have a
                          gradient background on the parent windows and the GroupBox is on the
                          position 50,50 then the background is capture from the Parent from the
                          position 0,0 which is wrong, because the GroupBox doesn't looks like
                          transparent in at all, has the gradient translated)

                          3) On the Controls that accept Color.Transpare nt, if you have a control on
                          Color.Transpare nt color and there is another control behind it (is not child
                          or parent, they have the same parent), Windows just capture the parent
                          Background which is wrong again, because you can't see the control that is
                          behind him.



                          So, what I did is inherit every control of windows, create my own BackBuffer
                          where I keep all my window status and changes, avoid call to
                          OnPaintBackgrou nd, and I take the process to draw the portion that windows
                          ask me to redraw with my own BackBuffer.



                          So, All this process is standard for every control and work really good,
                          then I can get "true" transparency and you don't see the difference on
                          performance.



                          But the code is ugly, because I have the same method implementation like 10
                          times!!!



                          Then the only that I need is consolidate my functionality on just one single
                          Class, Interface, Method or whatever I need.

                          On C++ if you do multi-inheritance then I can get what I'm looking for.



                          So, there is some way to emulate multi-inheritance on C#?????



                          I though interface was the answer. I see may be interface can't do too much
                          here, then some idea???



                          Thanks,

                          Gustavo.



                          P.S.: I think this is a very commun problem where you have to add
                          funcionality to thirdparty classes where you have to inherit from each one
                          of them and you have to share code for all of them.



                          "Anon" <Anon@Anon.Anon > wrote in message
                          news:7tyfb.2154 35$mp.133809@rw crnsc51.ops.asp .att.net...[color=blue]
                          > Can you implement the logic into a function (if VB) or static method in a
                          > class (VB or C#). Then for a control, implement your new interface and in
                          > the method of the implemented interface just pass the call onto the[/color]
                          function[color=blue]
                          > or shared method?
                          >
                          >
                          >
                          > "Franco Gustavo" <gfranco@inunti us.com> wrote in message
                          > news:uSkgoXmiDH A.3660@tk2msftn gp13.phx.gbl...[color=green]
                          > > But Control doesn't do anything that I want.
                          > >
                          > > Basically, I want derive from Label, Panel, GroupBox, CheckBox,[/color]
                          > RadioButton,[color=green]
                          > > etc. and add my extended funcionalities
                          > >
                          > > The Class control doesn't have any funcionality.
                          > >
                          > > On that case if I derived from Control I have to rewrite each windows
                          > > control from scratch wich is "not possible", doesn't make sense.
                          > >
                          > > Thanks,
                          > > Gustavo.
                          > >
                          > > "Sherif ElMetainy" <elmeteny.NOSPA M@wayout.net.NO SPAM> wrote in message
                          > > news:%23yrvKOmi DHA.1048@TK2MSF TNGP11.phx.gbl. ..[color=darkred]
                          > > > Hello
                          > > >
                          > > > Unlike C++, C# doesn't support multiple implementaion inheritance. But[/color]
                          > > your[color=darkred]
                          > > > problem can be solved by deriving the class[/color][/color][/color]
                          ExtendedControl Funcionality[color=blue][color=green]
                          > > from[color=darkred]
                          > > > Control and deriving your class from ExtendedControl Funcionality.
                          > > >
                          > > > Best regards,
                          > > >
                          > > > Sherif
                          > > >
                          > > >
                          > > > "Franco Gustavo" <gfranco@inunti us.com> wrote in message
                          > > > news:#hz4qCmiDH A.1564@tk2msftn gp13.phx.gbl...
                          > > > > Hi,
                          > > > >
                          > > > >
                          > > > >
                          > > > > Please help me to understand this, because I don't see what I'm[/color][/color]
                          > missing.[color=green][color=darkred]
                          > > > >
                          > > > >
                          > > > >
                          > > > > I was reading a lot of examples on Internet that explain that C#[/color][/color]
                          > doesn't[color=green][color=darkred]
                          > > > > implement multiple inheritance it implement multiple interfaces.
                          > > > >
                          > > > >
                          > > > >
                          > > > > So, I keep reading and reading and reading to see how can I resolve[/color][/color][/color]
                          my[color=blue][color=green][color=darkred]
                          > > > > problem with interfaces.
                          > > > >
                          > > > > The conclusion is I'm writing to all of you because I couldn't find[/color][/color]
                          > the[color=green][color=darkred]
                          > > > way
                          > > > > to resolve my problem.
                          > > > >
                          > > > >
                          > > > >
                          > > > > If I can create multiples interfaces and I have to implement the[/color][/color]
                          > methods[color=green][color=darkred]
                          > > > on
                          > > > > the derived class, then what's the big deal.
                          > > > >
                          > > > >
                          > > > >
                          > > > > I know if I declare a class that inherit from one interface is[/color][/color][/color]
                          useful[color=blue][color=green][color=darkred]
                          > > > > because for example
                          > > > >
                          > > > > I can create an Interface called Shape, and 3 Classes called Circle,
                          > > > > Rectangle, and Line.
                          > > > >
                          > > > > If on my interface I declare my method Draw(); and I implement on[/color][/color][/color]
                          each[color=blue][color=green][color=darkred]
                          > > > > derived class then I could do the next.
                          > > > >
                          > > > >
                          > > > >
                          > > > > IShape s = (IShape) AnyShapeObject;
                          > > > >
                          > > > > s.draw();
                          > > > >
                          > > > >
                          > > > >
                          > > > > I think is very useful and I used many times. But now the question[/color][/color][/color]
                          is[color=blue][color=green]
                          > > what[color=darkred]
                          > > > > is the similitude between Multiple Inheritance and Multiple[/color]
                          > > Interfaces????[color=darkred]
                          > > > I
                          > > > > don't see too much
                          > > > >
                          > > > >
                          > > > >
                          > > > > Why on Internet always speak for Multiple Inheritance and Multiple
                          > > > > Interfaces like they have a relation???
                          > > > >
                          > > > >
                          > > > >
                          > > > > My Case:
                          > > > >
                          > > > >
                          > > > >
                          > > > > I have many Windows Control and I'm inherit each one for create my[/color][/color][/color]
                          own[color=blue][color=green][color=darkred]
                          > > > > Controls.
                          > > > >
                          > > > > For example I want to add method called getVirtualSize( );
                          > > > >
                          > > > >
                          > > > >
                          > > > > I create and interface
                          > > > >
                          > > > > IVirtualSize
                          > > > >
                          > > > >
                          > > > >
                          > > > > It contain
                          > > > >
                          > > > > public getVirtualSize( );
                          > > > >
                          > > > >
                          > > > >
                          > > > > So, on my derived class I MUST implement my method getVirtualSize[/color][/color][/color]
                          and[color=blue][color=green][color=darkred]
                          > > > that's
                          > > > > it.
                          > > > >
                          > > > >
                          > > > >
                          > > > > Very nice!!!
                          > > > >
                          > > > >
                          > > > >
                          > > > > Now the real question is, I create a lot of logic on my paint[/color][/color][/color]
                          method;[color=blue][color=green]
                          > > this[color=darkred]
                          > > > > logic is exactly the same for all derived classes, why do I have to
                          > > > > implement this entire logic on each Control???
                          > > > >
                          > > > >
                          > > > >
                          > > > > With multiple inheritances you just create a class
                          > > > > ExtendedControl Funcionality and Implement a method OnPaintEx, and[/color][/color]
                          > really[color=green]
                          > > I[color=darkred]
                          > > > > have a nice source code, because my class[/color][/color][/color]
                          ExtendedControl Funcionality[color=blue][color=green]
                          > > has[color=darkred]
                          > > > > all the new extended functionality.
                          > > > >
                          > > > >
                          > > > >
                          > > > > Then how can I do the same with interfaces????
                          > > > >
                          > > > >
                          > > > >
                          > > > > I don't want to put my piece of code on every derived class, it is a[/color]
                          > > mess[color=darkred]
                          > > > > and very difficult to maintain, I want to centralize my source code[/color][/color]
                          > and[color=green]
                          > > in[color=darkred]
                          > > > > the same time I want to use many methods of the base classes, that[/color][/color]
                          > means[color=green]
                          > > I[color=darkred]
                          > > > > want to use all the protected methods that the controls offer to me
                          > > > because
                          > > > > OnPaintEx needs those.
                          > > > >
                          > > > >
                          > > > >
                          > > > > Really, here is only one example, the reality is that is a lot of[/color][/color]
                          > source[color=green][color=darkred]
                          > > > > code that I "should" implement on every Control, I don't want to do[/color]
                          > > that.[color=darkred]
                          > > > >
                          > > > >
                          > > > >
                          > > > > Thanks, the answers will be really appreciated.
                          > > > >
                          > > > > Gustavo.
                          > > > >
                          > > > >
                          > > > >
                          > > > >
                          > > >
                          > > >[/color]
                          > >
                          > >[/color]
                          >
                          >[/color]


                          Comment

                          • Fergus Cooney

                            #14
                            Re: Interfaces, Big Deal!!

                            Hi Anon,

                            In this instance, the problem with off-loading the functionality to
                            another Class or Module and passing the target object in, is that it would not
                            have access to the target's protected and/or private members.

                            In any case, that is just one example that frustrates Franco - as a
                            general solution there would be many cases where it's a workable but messy.

                            In my main response to Franco, I mention a linked-list Capability that I
                            have had to implement using an Interface. This does actually work by sending
                            the object to a worker Class to traverse the list. The method works, but it
                            suffers because I have to make the actual link fields, Prev and Next, public,
                            as my worker needs access to them. There are also issues with casting and
                            type-safety. I can't prevent a programmer from inserting a Widget into a
                            linked list of Thingies. As I'm the programmer, that's not going to happen,
                            but I would prefer to have my carpets tacked down rather than watch my feet.

                            Regards,
                            Fergus


                            Comment

                            • Fergus Cooney

                              #15
                              Re: Interfaces, Big Deal!!

                              Hi Anon,

                              In this instance, the problem with off-loading the functionality to
                              another Class or Module and passing the target object in, is that it would not
                              have access to the target's protected and/or private members.

                              In any case, that is just one example that frustrates Franco - as a
                              general solution there would be many cases where it's a workable but messy.

                              In my main response to Franco, I mention a linked-list Capability that I
                              have had to implement using an Interface. This does actually work by sending
                              the object to a worker Class to traverse the list. The method works, but it
                              suffers because I have to make the actual link fields, Prev and Next, public,
                              as my worker needs access to them. There are also issues with casting and
                              type-safety. I can't prevent a programmer from inserting a Widget into a
                              linked list of Thingies. As I'm the programmer, that's not going to happen,
                              but I would prefer to have my carpets tacked down rather than watch my feet.

                              Regards,
                              Fergus


                              Comment

                              Working...