Interfaces

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Duncan  McNutt .[FTSE]

    Interfaces

    Why does code derive from for example, IComparer

    ie,

    class SomeClass : IComparer
    {
    public SomeClass()
    {
    }

    public int Compare(object x, object y)
    {
    return someInt;
    }
    }


    When it just uses that and could have done without deriving ICompare and
    got the same result.

    class SomeClass
    {
    public SomeClass()
    {
    }

    public int Compare(object x, object y)
    {
    return someInt;
    }
    }

    --

    Duncan McNutt
    Microsoft Product Deactivation Team
    --



  • Duncan  McNutt .[FTSE]

    #2
    Re: Interfaces

    And another question...

    Because SomeClass derives from the IComparer interface


    if i use SomeClass as a base of another like...

    class SomeNewClass : SomeClass
    {
    public SomeNewClass()
    {
    }
    }

    Would that above fail due to no Compare method as SomeClass is derived from
    ICompare and it MUST implement Compare.. like..

    class SomeNewClass : SomeClass
    {
    public SomeNewClass()
    {
    }

    public int Compare(object x, object y)
    {
    return someInt;
    }
    }

    The above would work.

    Do i understand this correctly?

    --

    Duncan McNutt
    Microsoft Product Deactivation Team
    --


    " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
    news:uLBzK$kZDH A.2668@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Why does code derive from for example, IComparer
    >
    > ie,
    >
    > class SomeClass : IComparer
    > {
    > public SomeClass()
    > {
    > }
    >
    > public int Compare(object x, object y)
    > {
    > return someInt;
    > }
    > }
    >
    >
    > When it just uses that and could have done without deriving ICompare[/color]
    and[color=blue]
    > got the same result.
    >
    > class SomeClass
    > {
    > public SomeClass()
    > {
    > }
    >
    > public int Compare(object x, object y)
    > {
    > return someInt;
    > }
    > }
    >
    > --
    >
    > Duncan McNutt
    > Microsoft Product Deactivation Team
    > --
    >
    >
    >[/color]


    Comment

    • Ignacio Machin

      #3
      Re: Interfaces

      Hi Duncan,

      You do not derive from an interface, you implement it, there is a diference,
      an interface is like a template, it has no implementation it only assure
      that the classes that implement it have a predefined setof methods ( the
      interface ) , when you derive from a class you extend that class, add new
      functionality. you do not do that with an interface.

      Hope this help,

      --
      Ignacio Machin,
      ignacio.machin AT dot.state.fl.us
      Florida Department Of Transportation


      " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
      news:uLBzK$kZDH A.2668@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Why does code derive from for example, IComparer
      >
      > ie,
      >
      > class SomeClass : IComparer
      > {
      > public SomeClass()
      > {
      > }
      >
      > public int Compare(object x, object y)
      > {
      > return someInt;
      > }
      > }
      >
      >
      > When it just uses that and could have done without deriving ICompare[/color]
      and[color=blue]
      > got the same result.
      >
      > class SomeClass
      > {
      > public SomeClass()
      > {
      > }
      >
      > public int Compare(object x, object y)
      > {
      > return someInt;
      > }
      > }
      >
      > --
      >
      > Duncan McNutt
      > Microsoft Product Deactivation Team
      > --
      >
      >
      >[/color]


      Comment

      • Duncan  McNutt .[FTSE]

        #4
        Re: Interfaces

        oh well yeah oops :D wasnt thinking *gets coffee*

        So why inherit from ICompare when its just as easy to implement Compare
        anyway and its derived.

        --

        Duncan McNutt
        Microsoft Product Deactivation Team
        --


        "Peter Vidler" <pvidler@gawab. com> wrote in message
        news:bjp0b.27$g c6.35789@newsfe p1-win.server.ntli .net...[color=blue]
        > Hi,
        >[color=green]
        > > Would that above fail due to no Compare method as SomeClass is
        > > derived from ICompare and it MUST implement Compare.. like..[/color]
        >
        > No, because SomeNewClass will inherit the implementation from SomeClass.[/color]
        I'm[color=blue]
        > almost certain of it ;)
        >
        > Pete
        >
        >[/color]


        Comment

        • Duncan  McNutt .[FTSE]

          #5
          Re: Interfaces

          Yeah I understand an Interface is a contract, that must be implemented but I
          see code that has implemented that interface but why would it need to when
          it can just as easily implement it anyway and not have tim use ICompare in
          the class definition.

          Whats to stop me just coding a public int Compare(object x, object y) method
          anyway without referring to IComapre?



          --

          Duncan McNutt
          Microsoft Product Deactivation Team
          --


          "Ignacio Machin" <ignacio.mach in AT dot.state.fl.us > wrote in message
          news:uL48cNlZDH A.3768@tk2msftn gp13.phx.gbl...[color=blue]
          > Hi Duncan,
          >
          > You do not derive from an interface, you implement it, there is a[/color]
          diference,[color=blue]
          > an interface is like a template, it has no implementation it only assure
          > that the classes that implement it have a predefined setof methods ( the
          > interface ) , when you derive from a class you extend that class, add new
          > functionality. you do not do that with an interface.
          >
          > Hope this help,
          >
          > --
          > Ignacio Machin,
          > ignacio.machin AT dot.state.fl.us
          > Florida Department Of Transportation
          >
          >
          > " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
          > news:uLBzK$kZDH A.2668@TK2MSFTN GP09.phx.gbl...[color=green]
          > > Why does code derive from for example, IComparer
          > >
          > > ie,
          > >
          > > class SomeClass : IComparer
          > > {
          > > public SomeClass()
          > > {
          > > }
          > >
          > > public int Compare(object x, object y)
          > > {
          > > return someInt;
          > > }
          > > }
          > >
          > >
          > > When it just uses that and could have done without deriving ICompare[/color]
          > and[color=green]
          > > got the same result.
          > >
          > > class SomeClass
          > > {
          > > public SomeClass()
          > > {
          > > }
          > >
          > > public int Compare(object x, object y)
          > > {
          > > return someInt;
          > > }
          > > }
          > >
          > > --
          > >
          > > Duncan McNutt
          > > Microsoft Product Deactivation Team
          > > --
          > >
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Ignacio Machin

            #6
            Re: Interfaces

            Hi Duncan,


            I would suggest you something, if you have this kind of doubt, try it !! ,
            do not missunderstand me, I believe that the best way to learn is
            experimenting, your code will not fail cause as I explained in the previous
            post when you derive you are extending therefore the new class gets all the
            parent's functionality.

            Hope this help,

            --
            Ignacio Machin,
            ignacio.machin AT dot.state.fl.us
            Florida Department Of Transportation


            " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
            news:ekcmmBlZDH A.1940@TK2MSFTN GP10.phx.gbl...[color=blue]
            > And another question...
            >
            > Because SomeClass derives from the IComparer interface
            >
            >
            > if i use SomeClass as a base of another like...
            >
            > class SomeNewClass : SomeClass
            > {
            > public SomeNewClass()
            > {
            > }
            > }
            >
            > Would that above fail due to no Compare method as SomeClass is derived[/color]
            from[color=blue]
            > ICompare and it MUST implement Compare.. like..
            >
            > class SomeNewClass : SomeClass
            > {
            > public SomeNewClass()
            > {
            > }
            >
            > public int Compare(object x, object y)
            > {
            > return someInt;
            > }
            > }
            >
            > The above would work.
            >
            > Do i understand this correctly?
            >
            > --
            >
            > Duncan McNutt
            > Microsoft Product Deactivation Team
            > --
            >
            >
            > " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
            > news:uLBzK$kZDH A.2668@TK2MSFTN GP09.phx.gbl...[color=green]
            > > Why does code derive from for example, IComparer
            > >
            > > ie,
            > >
            > > class SomeClass : IComparer
            > > {
            > > public SomeClass()
            > > {
            > > }
            > >
            > > public int Compare(object x, object y)
            > > {
            > > return someInt;
            > > }
            > > }
            > >
            > >
            > > When it just uses that and could have done without deriving ICompare[/color]
            > and[color=green]
            > > got the same result.
            > >
            > > class SomeClass
            > > {
            > > public SomeClass()
            > > {
            > > }
            > >
            > > public int Compare(object x, object y)
            > > {
            > > return someInt;
            > > }
            > > }
            > >
            > > --
            > >
            > > Duncan McNutt
            > > Microsoft Product Deactivation Team
            > > --
            > >
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Peter Vidler

              #7
              Re: Interfaces

              Hi,
              [color=blue]
              > So why inherit from ICompare when its just as easy to implement
              > Compare anyway and its derived.[/color]

              Because then you can use an object of that type wherever IComparer is asked
              for (i.e. calls to methods, etc). Otherwise there is no way to tell if an
              object supports the Compare method without having a reference to the exact
              type of the object.

              Pete


              Comment

              • Frank Drebin

                #8
                Re: Interfaces

                The key element is that the purpose of an interface is that you can write
                your code to a generic "interface" ..

                For example, say you have a Windows app that needs to connect to a
                datasource. That datasource could be a real database, a remote web service
                and also an offline file. But you want to abstract HOW the datasource gets
                it's data. If you couldn't abstract it, you'd have to write 3 versions of
                code mixed in with your main application - to do this.

                but instead, you could write your application to use the IDataAccess
                interface (this is an interface you write, it has Connect() Authenticate(),
                etc)..

                Then you have classes such as Database, WebService and OfflineAccess that
                implement that interface.

                So Interfaces aren't so much a small-scale time-saver, they make more and
                more sense the larger the app gets - and the purpose is to abstract the
                specific of how something gets done.

                Using your examples, if you write your application to use the IComparer
                interface:

                IComparer objMyComparer = new SomeClass();

                Since SomeClass implements IComparer - the above is valid. Imagine that you
                could have several different KINDS of comparers - and you would only need to
                write your new classes to implement that same IComparer interface.

                hope that helps..

                " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
                news:uLBzK$kZDH A.2668@TK2MSFTN GP09.phx.gbl...[color=blue]
                > Why does code derive from for example, IComparer
                >
                > ie,
                >
                > class SomeClass : IComparer
                > {
                > public SomeClass()
                > {
                > }
                >
                > public int Compare(object x, object y)
                > {
                > return someInt;
                > }
                > }
                >
                >
                > When it just uses that and could have done without deriving ICompare[/color]
                and[color=blue]
                > got the same result.
                >
                > class SomeClass
                > {
                > public SomeClass()
                > {
                > }
                >
                > public int Compare(object x, object y)
                > {
                > return someInt;
                > }
                > }
                >
                > --
                >
                > Duncan McNutt
                > Microsoft Product Deactivation Team
                > --
                >
                >
                >[/color]


                Comment

                • Duncan  McNutt .[FTSE]

                  #9
                  Re: Interfaces

                  Yeah but why must that class implement ICompare when it can just as easily
                  make a public Compare (obj , obj) method and be the same.



                  --

                  Duncan McNutt
                  Microsoft Product Deactivation Team
                  --


                  "Ignacio Machin" <ignacio.mach in AT dot.state.fl.us > wrote in message
                  news:uL48cNlZDH A.3768@tk2msftn gp13.phx.gbl...[color=blue]
                  > Hi Duncan,
                  >
                  > You do not derive from an interface, you implement it, there is a[/color]
                  diference,[color=blue]
                  > an interface is like a template, it has no implementation it only assure
                  > that the classes that implement it have a predefined setof methods ( the
                  > interface ) , when you derive from a class you extend that class, add new
                  > functionality. you do not do that with an interface.
                  >
                  > Hope this help,
                  >
                  > --
                  > Ignacio Machin,
                  > ignacio.machin AT dot.state.fl.us
                  > Florida Department Of Transportation
                  >
                  >
                  > " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
                  > news:uLBzK$kZDH A.2668@TK2MSFTN GP09.phx.gbl...[color=green]
                  > > Why does code derive from for example, IComparer
                  > >
                  > > ie,
                  > >
                  > > class SomeClass : IComparer
                  > > {
                  > > public SomeClass()
                  > > {
                  > > }
                  > >
                  > > public int Compare(object x, object y)
                  > > {
                  > > return someInt;
                  > > }
                  > > }
                  > >
                  > >
                  > > When it just uses that and could have done without deriving ICompare[/color]
                  > and[color=green]
                  > > got the same result.
                  > >
                  > > class SomeClass
                  > > {
                  > > public SomeClass()
                  > > {
                  > > }
                  > >
                  > > public int Compare(object x, object y)
                  > > {
                  > > return someInt;
                  > > }
                  > > }
                  > >
                  > > --
                  > >
                  > > Duncan McNutt
                  > > Microsoft Product Deactivation Team
                  > > --
                  > >
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • Duncan  McNutt .[FTSE]

                    #10
                    Re: Interfaces

                    yeah I know, i just wasnt thinking, caffine levels droped :D

                    But my question is, why implement ICompare when I can just as easily make
                    the method without reference to IComapre at all in the class.

                    What is the benifit.


                    --

                    Duncan McNutt
                    Microsoft Product Deactivation Team
                    --


                    "Ignacio Machin" <ignacio.mach in AT dot.state.fl.us > wrote in message
                    news:eAg#5QlZDH A.652@TK2MSFTNG P10.phx.gbl...[color=blue]
                    > Hi Duncan,
                    >
                    >
                    > I would suggest you something, if you have this kind of doubt, try it !![/color]
                    ,[color=blue]
                    > do not missunderstand me, I believe that the best way to learn is
                    > experimenting, your code will not fail cause as I explained in the[/color]
                    previous[color=blue]
                    > post when you derive you are extending therefore the new class gets all[/color]
                    the[color=blue]
                    > parent's functionality.
                    >
                    > Hope this help,
                    >
                    > --
                    > Ignacio Machin,
                    > ignacio.machin AT dot.state.fl.us
                    > Florida Department Of Transportation
                    >
                    >
                    > " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
                    > news:ekcmmBlZDH A.1940@TK2MSFTN GP10.phx.gbl...[color=green]
                    > > And another question...
                    > >
                    > > Because SomeClass derives from the IComparer interface
                    > >
                    > >
                    > > if i use SomeClass as a base of another like...
                    > >
                    > > class SomeNewClass : SomeClass
                    > > {
                    > > public SomeNewClass()
                    > > {
                    > > }
                    > > }
                    > >
                    > > Would that above fail due to no Compare method as SomeClass is derived[/color]
                    > from[color=green]
                    > > ICompare and it MUST implement Compare.. like..
                    > >
                    > > class SomeNewClass : SomeClass
                    > > {
                    > > public SomeNewClass()
                    > > {
                    > > }
                    > >
                    > > public int Compare(object x, object y)
                    > > {
                    > > return someInt;
                    > > }
                    > > }
                    > >
                    > > The above would work.
                    > >
                    > > Do i understand this correctly?
                    > >
                    > > --
                    > >
                    > > Duncan McNutt
                    > > Microsoft Product Deactivation Team
                    > > --
                    > >
                    > >
                    > > " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
                    > > news:uLBzK$kZDH A.2668@TK2MSFTN GP09.phx.gbl...[color=darkred]
                    > > > Why does code derive from for example, IComparer
                    > > >
                    > > > ie,
                    > > >
                    > > > class SomeClass : IComparer
                    > > > {
                    > > > public SomeClass()
                    > > > {
                    > > > }
                    > > >
                    > > > public int Compare(object x, object y)
                    > > > {
                    > > > return someInt;
                    > > > }
                    > > > }
                    > > >
                    > > >
                    > > > When it just uses that and could have done without deriving[/color][/color][/color]
                    ICompare[color=blue][color=green]
                    > > and[color=darkred]
                    > > > got the same result.
                    > > >
                    > > > class SomeClass
                    > > > {
                    > > > public SomeClass()
                    > > > {
                    > > > }
                    > > >
                    > > > public int Compare(object x, object y)
                    > > > {
                    > > > return someInt;
                    > > > }
                    > > > }
                    > > >
                    > > > --
                    > > >
                    > > > Duncan McNutt
                    > > > Microsoft Product Deactivation Team
                    > > > --
                    > > >
                    > > >
                    > > >[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • Duncan  McNutt .[FTSE]

                      #11
                      Re: Interfaces

                      ahh ok, thanks that clears it up.

                      I just saw it in a small snipit of code on a little project and It just
                      didnt make sense why he used it for that example but yeah i can see the
                      benifit of that when scaling it up :D

                      So, would it be good practice to implement such interfaces where possible,
                      regardless of size, just for future or where basically I can see a specific
                      need for generic implementation?

                      --

                      Duncan McNutt
                      Microsoft Product Deactivation Team
                      --


                      "Frank Drebin" <noemail@imsick ofspam.com> wrote in message
                      news:Usp0b.2723 3$Vx2.12517799@ newssvr28.news. prodigy.com...[color=blue]
                      > The key element is that the purpose of an interface is that you can write
                      > your code to a generic "interface" ..
                      >
                      > For example, say you have a Windows app that needs to connect to a
                      > datasource. That datasource could be a real database, a remote web service
                      > and also an offline file. But you want to abstract HOW the datasource gets
                      > it's data. If you couldn't abstract it, you'd have to write 3 versions of
                      > code mixed in with your main application - to do this.
                      >
                      > but instead, you could write your application to use the IDataAccess
                      > interface (this is an interface you write, it has Connect()[/color]
                      Authenticate(),[color=blue]
                      > etc)..
                      >
                      > Then you have classes such as Database, WebService and OfflineAccess that
                      > implement that interface.
                      >
                      > So Interfaces aren't so much a small-scale time-saver, they make more and
                      > more sense the larger the app gets - and the purpose is to abstract the
                      > specific of how something gets done.
                      >
                      > Using your examples, if you write your application to use the IComparer
                      > interface:
                      >
                      > IComparer objMyComparer = new SomeClass();
                      >
                      > Since SomeClass implements IComparer - the above is valid. Imagine that[/color]
                      you[color=blue]
                      > could have several different KINDS of comparers - and you would only need[/color]
                      to[color=blue]
                      > write your new classes to implement that same IComparer interface.
                      >
                      > hope that helps..
                      >
                      > " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
                      > news:uLBzK$kZDH A.2668@TK2MSFTN GP09.phx.gbl...[color=green]
                      > > Why does code derive from for example, IComparer
                      > >
                      > > ie,
                      > >
                      > > class SomeClass : IComparer
                      > > {
                      > > public SomeClass()
                      > > {
                      > > }
                      > >
                      > > public int Compare(object x, object y)
                      > > {
                      > > return someInt;
                      > > }
                      > > }
                      > >
                      > >
                      > > When it just uses that and could have done without deriving ICompare[/color]
                      > and[color=green]
                      > > got the same result.
                      > >
                      > > class SomeClass
                      > > {
                      > > public SomeClass()
                      > > {
                      > > }
                      > >
                      > > public int Compare(object x, object y)
                      > > {
                      > > return someInt;
                      > > }
                      > > }
                      > >
                      > > --
                      > >
                      > > Duncan McNutt
                      > > Microsoft Product Deactivation Team
                      > > --
                      > >
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      • Peter Vidler

                        #12
                        Re: Interfaces

                        Hi,
                        [color=blue]
                        > Whats to stop me just coding a public int Compare(object x, object y)[/color]

                        Because my CompareStuff method ("public int CompareStuff(IC omparer[]
                        stuff)") couldn't use your class unless you implement IComparer.

                        Hope that syntax was correct :)

                        Pete


                        Comment

                        • Ashish

                          #13
                          Re: Interfaces

                          Read some OOP book before starting on C#. Advise of a wellwisher...
                          Ashish

                          " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
                          news:uLBzK$kZDH A.2668@TK2MSFTN GP09.phx.gbl...[color=blue]
                          > Why does code derive from for example, IComparer
                          >
                          > ie,
                          >
                          > class SomeClass : IComparer
                          > {
                          > public SomeClass()
                          > {
                          > }
                          >
                          > public int Compare(object x, object y)
                          > {
                          > return someInt;
                          > }
                          > }
                          >
                          >
                          > When it just uses that and could have done without deriving ICompare[/color]
                          and[color=blue]
                          > got the same result.
                          >
                          > class SomeClass
                          > {
                          > public SomeClass()
                          > {
                          > }
                          >
                          > public int Compare(object x, object y)
                          > {
                          > return someInt;
                          > }
                          > }
                          >
                          > --
                          >
                          > Duncan McNutt
                          > Microsoft Product Deactivation Team
                          > --
                          >
                          >
                          >[/color]


                          Comment

                          • Frank Drebin

                            #14
                            Re: Interfaces

                            Since I've started developing in OO - I've been learning that the more you
                            can abstract, the better...

                            So it really is just a trade-off of - how much time (now, and in the future)
                            will writing an interface save me.. versus how long will it take me to
                            write.

                            But as a general rule, I'm a big fan abstracting as much as possible,
                            whenever possible...

                            " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
                            news:%23xyXjTlZ DHA.1680@tk2msf tngp13.phx.gbl. ..[color=blue]
                            > ahh ok, thanks that clears it up.
                            >
                            > I just saw it in a small snipit of code on a little project and It just
                            > didnt make sense why he used it for that example but yeah i can see the
                            > benifit of that when scaling it up :D
                            >
                            > So, would it be good practice to implement such interfaces where possible,
                            > regardless of size, just for future or where basically I can see a[/color]
                            specific[color=blue]
                            > need for generic implementation?
                            >
                            > --
                            >
                            > Duncan McNutt
                            > Microsoft Product Deactivation Team
                            > --
                            >
                            >
                            > "Frank Drebin" <noemail@imsick ofspam.com> wrote in message
                            > news:Usp0b.2723 3$Vx2.12517799@ newssvr28.news. prodigy.com...[color=green]
                            > > The key element is that the purpose of an interface is that you can[/color][/color]
                            write[color=blue][color=green]
                            > > your code to a generic "interface" ..
                            > >
                            > > For example, say you have a Windows app that needs to connect to a
                            > > datasource. That datasource could be a real database, a remote web[/color][/color]
                            service[color=blue][color=green]
                            > > and also an offline file. But you want to abstract HOW the datasource[/color][/color]
                            gets[color=blue][color=green]
                            > > it's data. If you couldn't abstract it, you'd have to write 3 versions[/color][/color]
                            of[color=blue][color=green]
                            > > code mixed in with your main application - to do this.
                            > >
                            > > but instead, you could write your application to use the IDataAccess
                            > > interface (this is an interface you write, it has Connect()[/color]
                            > Authenticate(),[color=green]
                            > > etc)..
                            > >
                            > > Then you have classes such as Database, WebService and OfflineAccess[/color][/color]
                            that[color=blue][color=green]
                            > > implement that interface.
                            > >
                            > > So Interfaces aren't so much a small-scale time-saver, they make more[/color][/color]
                            and[color=blue][color=green]
                            > > more sense the larger the app gets - and the purpose is to abstract the
                            > > specific of how something gets done.
                            > >
                            > > Using your examples, if you write your application to use the IComparer
                            > > interface:
                            > >
                            > > IComparer objMyComparer = new SomeClass();
                            > >
                            > > Since SomeClass implements IComparer - the above is valid. Imagine that[/color]
                            > you[color=green]
                            > > could have several different KINDS of comparers - and you would only[/color][/color]
                            need[color=blue]
                            > to[color=green]
                            > > write your new classes to implement that same IComparer interface.
                            > >
                            > > hope that helps..
                            > >
                            > > " Duncan McNutt .[FTSE]" <pitmaster@127. 0.0.701> wrote in message
                            > > news:uLBzK$kZDH A.2668@TK2MSFTN GP09.phx.gbl...[color=darkred]
                            > > > Why does code derive from for example, IComparer
                            > > >
                            > > > ie,
                            > > >
                            > > > class SomeClass : IComparer
                            > > > {
                            > > > public SomeClass()
                            > > > {
                            > > > }
                            > > >
                            > > > public int Compare(object x, object y)
                            > > > {
                            > > > return someInt;
                            > > > }
                            > > > }
                            > > >
                            > > >
                            > > > When it just uses that and could have done without deriving[/color][/color][/color]
                            ICompare[color=blue][color=green]
                            > > and[color=darkred]
                            > > > got the same result.
                            > > >
                            > > > class SomeClass
                            > > > {
                            > > > public SomeClass()
                            > > > {
                            > > > }
                            > > >
                            > > > public int Compare(object x, object y)
                            > > > {
                            > > > return someInt;
                            > > > }
                            > > > }
                            > > >
                            > > > --
                            > > >
                            > > > Duncan McNutt
                            > > > Microsoft Product Deactivation Team
                            > > > --
                            > > >
                            > > >
                            > > >[/color]
                            > >
                            > >[/color]
                            >
                            >[/color]


                            Comment

                            • Jon Skeet

                              #15
                              Re: Interfaces

                              Duncan McNutt .[FTSE] <pitmaster@127. 0.0.701> wrote:[color=blue]
                              > Why does code derive from for example, IComparer
                              >
                              > ie,
                              >
                              > class SomeClass : IComparer
                              > {
                              > public SomeClass()
                              > {
                              > }
                              >
                              > public int Compare(object x, object y)
                              > {
                              > return someInt;
                              > }
                              > }
                              >
                              >
                              > When it just uses that and could have done without deriving ICompare and
                              > got the same result.[/color]

                              No you didn't. You can't use an instance of SomeClass to provide the
                              comparisons for Array.Sort, for instance, unless is implements
                              IComparer.

                              --
                              Jon Skeet - <skeet@pobox.co m>
                              Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                              If replying to the group, please do not mail me too

                              Comment

                              Working...