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.
  • G Gary Wheeler

    One of my favorite things about C# as opposed to C++ is that they don't get wrapped around the axle over adding useful features that piss off the language dilettantes. This is a useful feature. It lets you implement an interface change piecemeal, rather than forcing you to implement the change in one great steaming pile. You can even have the default implementation perform an assert to help ensure you've caught all cases. The C++ folks would flagellate themselves for years over this, there would be dozens of half-baked implementations with wildly conflicting implementations, and when the standard was finally issued, no one would care.

    Software Zen: delete this;

    J Offline
    J Offline
    jsc42
    wrote on last edited by
    #41

    Gary Wheeler wrote:

    This is a useful feature. It lets you implement an interface change piecemeal, rather than forcing you to implement the change in one great steaming pile

    You are right! Making a tiny mod to an existing interface means every use of the interface in dozens of locations needs to be updated. Having a default method would mean that no changes to existing code would be needed. Only code that wanted to exploit the new feature(s) need implement the new method(s). Of course, you can avoid this already by creating a new interface that inherits the old one and just converting occasions that need the new methods from the old interface name to the new interface name.

    1 Reply Last reply
    0
    • D David A Gray

      Quote:

      Take List as an example. Trying to compare an instance of List to an instance of type T is pointless; they are completely different things. What List does, though, is provide a container and enumeration strategy for instances of type T; or operations, if you will. I think that's a far cry from "a specialized type of abstract base class".

      A generic type, such as List provides a generic (abstract!) implementation of a List, which has well-defined properties and methods, such as Add, Remove, Sort, and Count, whereas a concrete instance, such as List implements the generic List behaviors for a list of integers. Furthermore, you cannot instantiate a List, any more than you can instantiate any other abstract base class, such as System.IO.Stream; you must instantiate a List, where OfType is some concrete type.

      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
      #42

      o.O List is a concrete type. It is not abstract. The fact that you need to pass in a generic parameter makes it no less concrete. I do not need to write a new implementation for List, or List, or List>, because List is concrete already. Otherwise you'd need to write an implementation for every type T you might pass in, which would, IMO, completely defeat the purpose of generics.

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

      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