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. General Programming
  3. C#
  4. Interfaces with code in them

Interfaces with code in them

Scheduled Pinned Locked Moved C#
questioncsharpoop
5 Posts 4 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.
  • R Offline
    R Offline
    Rob Philpott
    wrote on last edited by
    #1

    Just had one of those moments where I thought I was going mad. I had put a method implementation in an interface (not quite sure how I got there) and not only did the compiler not complain, it actually worked. After several minutes questioning my sanity, I recalled something new in the language about this, and it turns out its C#8 'default implementations' or some such. Thus the central tenet of an interface 'can't contain an implementation' is gone, well sort of. I think its probably the case that the source can contain an implementation, but its just lifted into the implementer by the compiler, which I guess creates a type of static polymorphism. Haven't actually read about it too closely so that might be wrong. There certainly seems to be parallels to a virtual function. I really feel I need to sit down and think out my understanding and implications of all this now. It warrants the question whether they are messing with the language too much? As it turns out this feature is of use to me if I don't think about it too much, allowing me to provide a simple helper property which just combines other properties, but it seems an interface is just that bit closer to an abstract class now. I have to say these updates to the language generally aren't met with pleasure by me. They're just more things I feel I need to keep on top on rather than things that actually make my life easier. Old dog maybe, I still haven't got over extension methods yet!

    Regards, Rob Philpott.

    Richard DeemingR L 2 Replies Last reply
    0
    • R Rob Philpott

      Just had one of those moments where I thought I was going mad. I had put a method implementation in an interface (not quite sure how I got there) and not only did the compiler not complain, it actually worked. After several minutes questioning my sanity, I recalled something new in the language about this, and it turns out its C#8 'default implementations' or some such. Thus the central tenet of an interface 'can't contain an implementation' is gone, well sort of. I think its probably the case that the source can contain an implementation, but its just lifted into the implementer by the compiler, which I guess creates a type of static polymorphism. Haven't actually read about it too closely so that might be wrong. There certainly seems to be parallels to a virtual function. I really feel I need to sit down and think out my understanding and implications of all this now. It warrants the question whether they are messing with the language too much? As it turns out this feature is of use to me if I don't think about it too much, allowing me to provide a simple helper property which just combines other properties, but it seems an interface is just that bit closer to an abstract class now. I have to say these updates to the language generally aren't met with pleasure by me. They're just more things I feel I need to keep on top on rather than things that actually make my life easier. Old dog maybe, I still haven't got over extension methods yet!

      Regards, Rob Philpott.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Yes, default interface methods look like a complete mess to me:

      Safely update interfaces using default interface methods in C# | Microsoft Docs[^]:

      Interfaces can now include static members, including fields and methods. Different access modifiers are also enabled. The additional fields are private, the new method is public. Any of the modifiers are allowed on interface members.

      Thankfully, it's restricted to .NET Core 3.0 or later. With no SSRS support in .NET Core / .NET 5, we're sticking with .NET Framework 4.8, so our interfaces shall remain untainted by this abomination. If you're interested, Matt Warren digs into the low-level "behind the scenes" details here: Under the hood of "Default Interface Methods" · Performance is a Feature![^] Oh, and things are set to get even worse in C# 10: [Proposal]: Static abstract members in interfaces · Issue #4436 · dotnet/csharplang · GitHub[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      R pkfoxP 2 Replies Last reply
      0
      • Richard DeemingR Richard Deeming

        Yes, default interface methods look like a complete mess to me:

        Safely update interfaces using default interface methods in C# | Microsoft Docs[^]:

        Interfaces can now include static members, including fields and methods. Different access modifiers are also enabled. The additional fields are private, the new method is public. Any of the modifiers are allowed on interface members.

        Thankfully, it's restricted to .NET Core 3.0 or later. With no SSRS support in .NET Core / .NET 5, we're sticking with .NET Framework 4.8, so our interfaces shall remain untainted by this abomination. If you're interested, Matt Warren digs into the low-level "behind the scenes" details here: Under the hood of "Default Interface Methods" · Performance is a Feature![^] Oh, and things are set to get even worse in C# 10: [Proposal]: Static abstract members in interfaces · Issue #4436 · dotnet/csharplang · GitHub[^]


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        R Offline
        R Offline
        Rob Philpott
        wrote on last edited by
        #3

        static members as well?? Well, at this point that makes entirely zero sense to me. Oh, the horror..

        Regards, Rob Philpott.

        1 Reply Last reply
        0
        • R Rob Philpott

          Just had one of those moments where I thought I was going mad. I had put a method implementation in an interface (not quite sure how I got there) and not only did the compiler not complain, it actually worked. After several minutes questioning my sanity, I recalled something new in the language about this, and it turns out its C#8 'default implementations' or some such. Thus the central tenet of an interface 'can't contain an implementation' is gone, well sort of. I think its probably the case that the source can contain an implementation, but its just lifted into the implementer by the compiler, which I guess creates a type of static polymorphism. Haven't actually read about it too closely so that might be wrong. There certainly seems to be parallels to a virtual function. I really feel I need to sit down and think out my understanding and implications of all this now. It warrants the question whether they are messing with the language too much? As it turns out this feature is of use to me if I don't think about it too much, allowing me to provide a simple helper property which just combines other properties, but it seems an interface is just that bit closer to an abstract class now. I have to say these updates to the language generally aren't met with pleasure by me. They're just more things I feel I need to keep on top on rather than things that actually make my life easier. Old dog maybe, I still haven't got over extension methods yet!

          Regards, Rob Philpott.

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

          Interfaces are somewhat lame, but needed; extensions work here and there; inheritance is "bad". I think it provides some middle ground. If it avoids having to implement every interface member, all the time, that's good too.

          It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

          1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Yes, default interface methods look like a complete mess to me:

            Safely update interfaces using default interface methods in C# | Microsoft Docs[^]:

            Interfaces can now include static members, including fields and methods. Different access modifiers are also enabled. The additional fields are private, the new method is public. Any of the modifiers are allowed on interface members.

            Thankfully, it's restricted to .NET Core 3.0 or later. With no SSRS support in .NET Core / .NET 5, we're sticking with .NET Framework 4.8, so our interfaces shall remain untainted by this abomination. If you're interested, Matt Warren digs into the low-level "behind the scenes" details here: Under the hood of "Default Interface Methods" · Performance is a Feature![^] Oh, and things are set to get even worse in C# 10: [Proposal]: Static abstract members in interfaces · Issue #4436 · dotnet/csharplang · GitHub[^]


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            pkfoxP Offline
            pkfoxP Offline
            pkfox
            wrote on last edited by
            #5

            God what a dogs breakfast

            "I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP

            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