Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Blurring the Lines Between Interfaces and Abstract Classes

Blurring the Lines Between Interfaces and Abstract Classes

Scheduled Pinned Locked Moved The Lounge
csharpcomhelpquestion
42 Posts 13 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D David A Gray

    As I read https://devblogs.microsoft.com/dotnet/default-implementations-in-interfaces/?utm\_source=Main&utm\_campaign=34ca4f5665-EMAIL\_CAMPAIGN\_2017\_12\_19\_COPY\_01&utm\_medium=email&utm\_term=0\_aa2f642d94-34ca4f5665-227561569&mc\_cid=34ca4f5665&mc\_eid=8087c9508d, the first thing that came to mind is that this new feature, though it's clearly cool and useful, blurs the line between interfaces and abstract classes.

    David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

    C Offline
    C Offline
    Chris Maunder
    wrote on last edited by
    #3

    Maybe what they needed was a versioning system for interfaces and you lock (or not) your implementation to a given version. I get the motivation, but it seems like they are hacking the language a little too much. Why would someone both with an abstract class?

    cheers Chris Maunder

    D M J 3 Replies Last reply
    0
    • D David A Gray

      As I read https://devblogs.microsoft.com/dotnet/default-implementations-in-interfaces/?utm\_source=Main&utm\_campaign=34ca4f5665-EMAIL\_CAMPAIGN\_2017\_12\_19\_COPY\_01&utm\_medium=email&utm\_term=0\_aa2f642d94-34ca4f5665-227561569&mc\_cid=34ca4f5665&mc\_eid=8087c9508d, the first thing that came to mind is that this new feature, though it's clearly cool and useful, blurs the line between interfaces and abstract classes.

      David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

      D Offline
      D Offline
      Dean Roddey
      wrote on last edited by
      #4

      Is this the programming technique video that Emily Ratajkowski was in?

      Explorans limites defectum

      L D 2 Replies Last reply
      0
      • D Dean Roddey

        Is this the programming technique video that Emily Ratajkowski was in?

        Explorans limites defectum

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #5

        I don't know about Emily Ratajkowski, but I saw a video where Karlie Kloss explains how to program a rectangle that is twice as wide as it is tall: [Karlie Kloss explains how to use math with the artist in Code Studio - YouTube](https://www.youtube.com/watch?v=BGeT8IyKd2M)

        1 Reply Last reply
        0
        • D Dean Roddey

          Is this the programming technique video that Emily Ratajkowski was in?

          Explorans limites defectum

          D Offline
          D Offline
          David A Gray
          wrote on last edited by
          #6

          No, it's a short article; there is a picture or two, but no video.

          David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

          D 1 Reply Last reply
          0
          • C Chris Maunder

            Maybe what they needed was a versioning system for interfaces and you lock (or not) your implementation to a given version. I get the motivation, but it seems like they are hacking the language a little too much. Why would someone both with an abstract class?

            cheers Chris Maunder

            D Offline
            D Offline
            David A Gray
            wrote on last edited by
            #7

            Quote:

            I get the motivation, but it seems like they are hacking the language a little too much. Why would someone both with an abstract class?

            That was my point.

            David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

            1 Reply Last reply
            0
            • D David A Gray

              No, it's a short article; there is a picture or two, but no video.

              David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

              D Offline
              D Offline
              Dean Roddey
              wrote on last edited by
              #8

              I weep for the world when you can't even make a good risque innuendo anymore...

              Explorans limites defectum

              P 1 Reply Last reply
              0
              • N Nathan Minier

                Sure, except that you can inherit multiple interfaces and you still can't instantiate one without an implementation. Architecturally, they still have highly different uses.

                "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                D Offline
                D Offline
                David A Gray
                wrote on last edited by
                #9

                Quote:

                Sure, except that you can inherit multiple interfaces and you still can't instantiate one without an implementation.

                Depending on how it is defined, it is possible to inherit an abstract class. Two cases in point are List and Dictionary. After all, generics are, for all practical purposes, abstract classes.

                Quote:

                Architecturally, they still have highly different uses.

                About that, I agree, so why muddy the waters with this new construct that is half interface and half virtual method?

                David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                1 Reply Last reply
                0
                • N Nathan Minier

                  Sure, except that you can inherit multiple interfaces and you still can't instantiate one without an implementation. Architecturally, they still have highly different uses.

                  "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                  D Offline
                  D Offline
                  David A Gray
                  wrote on last edited by
                  #10

                  Quote:

                  Sure, except that you can inherit multiple interfaces and you still can't instantiate one without an implementation.

                  Depending on how it is defined, it is possible to inherit an abstract class. Two cases in point are List and Dictionary. After all, generics are, for all practical purposes, abstract classes.

                  Quote:

                  Architecturally, they still have highly different uses.

                  About that, I agree, so why muddy the waters with this new construct that is half interface and half virtual method?

                  David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                  N 1 Reply Last reply
                  0
                  • D David A Gray

                    As I read https://devblogs.microsoft.com/dotnet/default-implementations-in-interfaces/?utm\_source=Main&utm\_campaign=34ca4f5665-EMAIL\_CAMPAIGN\_2017\_12\_19\_COPY\_01&utm\_medium=email&utm\_term=0\_aa2f642d94-34ca4f5665-227561569&mc\_cid=34ca4f5665&mc\_eid=8087c9508d, the first thing that came to mind is that this new feature, though it's clearly cool and useful, blurs the line between interfaces and abstract classes.

                    David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                    realJSOPR Offline
                    realJSOPR Offline
                    realJSOP
                    wrote on last edited by
                    #11

                    Interface default methods is a pointless "feature". Abstract classes are infinitely more useful than interfaces. I rarely use/create interfaces (I usually only use them when some .net feature demands it, such as IDisposable or INotifyPropertyChange. In either case, you still have to implement the abstract methods/properties, or the interface methods.

                    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                    -----
                    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                    -----
                    When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                    D D 2 Replies Last reply
                    0
                    • D Dean Roddey

                      I weep for the world when you can't even make a good risque innuendo anymore...

                      Explorans limites defectum

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #12

                      I'm sure you can. You just haven't.

                      D 1 Reply Last reply
                      0
                      • realJSOPR realJSOP

                        Interface default methods is a pointless "feature". Abstract classes are infinitely more useful than interfaces. I rarely use/create interfaces (I usually only use them when some .net feature demands it, such as IDisposable or INotifyPropertyChange. In either case, you still have to implement the abstract methods/properties, or the interface methods.

                        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                        -----
                        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                        -----
                        When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                        D Offline
                        D Offline
                        David A Gray
                        wrote on last edited by
                        #13

                        Quote:

                        Interface default methods is a pointless "feature".

                        Thank you for getting my point.

                        Quote:

                        Abstract classes are infinitely more useful than interfaces.

                        Absolutely!

                        Quote:

                        I rarely use/create interfaces (I usually only use them when some .net feature demands it, such as IDisposable or INotifyPropertyChange. In either case, you still have to implement the abstract methods/properties, or the interface methods.

                        My personal exception to that rule is IComparable, which I frequently implement, so that I can make collections of classes sortable and searchable.

                        David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                        M 1 Reply Last reply
                        0
                        • D David A Gray

                          Quote:

                          Sure, except that you can inherit multiple interfaces and you still can't instantiate one without an implementation.

                          Depending on how it is defined, it is possible to inherit an abstract class. Two cases in point are List and Dictionary. After all, generics are, for all practical purposes, abstract classes.

                          Quote:

                          Architecturally, they still have highly different uses.

                          About that, I agree, so why muddy the waters with this new construct that is half interface and half virtual method?

                          David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                          N Offline
                          N Offline
                          Nathan Minier
                          wrote on last edited by
                          #14

                          David A. Gray wrote:

                          After all, generics are, for all practical purposes, abstract classes.

                          I really don't agree with that. I think in general the purpose of really surface-level default implementations give you options for interacting with those implementations or to give a default error. That's mostly it, or at least that's all I'd use it for. I don't see that as muddying. I think it will result in much more composable code, and that's a valid purpose.

                          "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                          D 1 Reply Last reply
                          0
                          • N Nathan Minier

                            David A. Gray wrote:

                            After all, generics are, for all practical purposes, abstract classes.

                            I really don't agree with that. I think in general the purpose of really surface-level default implementations give you options for interacting with those implementations or to give a default error. That's mostly it, or at least that's all I'd use it for. I don't see that as muddying. I think it will result in much more composable code, and that's a valid purpose.

                            "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                            D Offline
                            D Offline
                            David A Gray
                            wrote on last edited by
                            #15

                            Quote:

                            David A. Gray wrote: After all, generics are, for all practical purposes, abstract classes. I really don't agree with that.

                            Please clarify. 1) You cannot directly implement a generic class. 2) The class provides default implementations of its methods to all instances. How, then, is a generic class anything more, nor less, than a specialized type of abstract base class?

                            David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                            N 1 Reply Last reply
                            0
                            • P PIEBALDconsult

                              I'm sure you can. You just haven't.

                              D Offline
                              D Offline
                              Dean Roddey
                              wrote on last edited by
                              #16

                              No, you are...

                              Explorans limites defectum

                              1 Reply Last reply
                              0
                              • D David A Gray

                                As I read https://devblogs.microsoft.com/dotnet/default-implementations-in-interfaces/?utm\_source=Main&utm\_campaign=34ca4f5665-EMAIL\_CAMPAIGN\_2017\_12\_19\_COPY\_01&utm\_medium=email&utm\_term=0\_aa2f642d94-34ca4f5665-227561569&mc\_cid=34ca4f5665&mc\_eid=8087c9508d, the first thing that came to mind is that this new feature, though it's clearly cool and useful, blurs the line between interfaces and abstract classes.

                                David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #17

                                I like it. Implement only the methods you really need and not bother about the rest. In Java I have listener interfaces with tons of methods that I will never need but have to put some empty stub code because I have to.

                                D 1 Reply Last reply
                                0
                                • C Chris Maunder

                                  Maybe what they needed was a versioning system for interfaces and you lock (or not) your implementation to a given version. I get the motivation, but it seems like they are hacking the language a little too much. Why would someone both with an abstract class?

                                  cheers Chris Maunder

                                  M Offline
                                  M Offline
                                  Matthew Dennis
                                  wrote on last edited by
                                  #18

                                  so maybe sealed methods on the interface? They are part of the interface but can't be implemented.

                                  "Time flies like an arrow. Fruit flies like a banana."

                                  L 1 Reply Last reply
                                  0
                                  • realJSOPR realJSOP

                                    Interface default methods is a pointless "feature". Abstract classes are infinitely more useful than interfaces. I rarely use/create interfaces (I usually only use them when some .net feature demands it, such as IDisposable or INotifyPropertyChange. In either case, you still have to implement the abstract methods/properties, or the interface methods.

                                    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                    -----
                                    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                    -----
                                    When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                                    D Offline
                                    D Offline
                                    Dean Roddey
                                    wrote on last edited by
                                    #19

                                    Maybe there's something about C# interfaces I don't get, but in general interfaces are extremely useful. I dunno about this particular aspect of them being discussed here, but in C++ at least they are crucial. Without them, you can't add polymorphic functionality to classes outside of the straight line inheritance mechanism. Do they not work anything like that in C#?

                                    Explorans limites defectum

                                    1 Reply Last reply
                                    0
                                    • D David A Gray

                                      Quote:

                                      Interface default methods is a pointless "feature".

                                      Thank you for getting my point.

                                      Quote:

                                      Abstract classes are infinitely more useful than interfaces.

                                      Absolutely!

                                      Quote:

                                      I rarely use/create interfaces (I usually only use them when some .net feature demands it, such as IDisposable or INotifyPropertyChange. In either case, you still have to implement the abstract methods/properties, or the interface methods.

                                      My personal exception to that rule is IComparable, which I frequently implement, so that I can make collections of classes sortable and searchable.

                                      David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                                      M Offline
                                      M Offline
                                      Matthew Dennis
                                      wrote on last edited by
                                      #20

                                      I like interfaces, but I find myself deriving abstract classes from the interface that I derive the implementation classes. I implement the common stuff in the abstract class and leave the rest abstract. This allows me to create multiple base abstract classes for different hierarchies of things that all implement the base interface, but have different common functionality.

                                      "Time flies like an arrow. Fruit flies like a banana."

                                      1 Reply Last reply
                                      0
                                      • L Lost User

                                        I like it. Implement only the methods you really need and not bother about the rest. In Java I have listener interfaces with tons of methods that I will never need but have to put some empty stub code because I have to.

                                        D Offline
                                        D Offline
                                        David A Gray
                                        wrote on last edited by
                                        #21

                                        Quote:

                                        I like it. Implement only the methods you really need and not bother about the rest. In Java I have listener interfaces with tons of methods that I will never need but have to put some empty stub code because I have to.

                                        Am I missing something, or are you stuck with some badly designed Java classes? IMO, for the most part, an abstract class should provide a default implementation of every method, perhaps marked as virtual. With that being said, I have one abstract class of my own devising that has one abstract method on it, which must, of course, be implemented by every heir. Since the method takes an enumerated type as its argument, and its work requires evaluating that enumeration by way of a switch block, the base class cannot implement it.

                                        David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                                        L 1 Reply Last reply
                                        0
                                        • D David A Gray

                                          As I read https://devblogs.microsoft.com/dotnet/default-implementations-in-interfaces/?utm\_source=Main&utm\_campaign=34ca4f5665-EMAIL\_CAMPAIGN\_2017\_12\_19\_COPY\_01&utm\_medium=email&utm\_term=0\_aa2f642d94-34ca4f5665-227561569&mc\_cid=34ca4f5665&mc\_eid=8087c9508d, the first thing that came to mind is that this new feature, though it's clearly cool and useful, blurs the line between interfaces and abstract classes.

                                          David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                                          M Offline
                                          M Offline
                                          Matthew Dennis
                                          wrote on last edited by
                                          #22

                                          They also allow you to extend the functionality of the entire Interface hierarchy of classes by adding new methods with implementations. Of course, you can already do this with Extension Methods, which allows you to extend things in the context of what your are doing, depending which extension methods you include in your project in your using directives. I can see use cases for both, but I really like Extension Methods for the ability to extend a class without having to do anything to the class itself. Very SOLID.

                                          "Time flies like an arrow. Fruit flies like a banana."

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups