Where did the concept of Interfaces come from?

后端 未结 18 2101
有刺的猬
有刺的猬 2021-01-11 18:45

In c#, we have interfaces. Where did these come from? They didn\'t exist in c++.

相关标签:
18条回答
  • 2021-01-11 19:11

    The earliest implementation of interfaces that I know of in computing came from CORBA.

    My understanding is that the concept came out of electrical and electronic engineering where a power outlet in a wall for instance can be used (and implemented) by anyone who knows the specification. Interfaces then provide the same flexibility programatically.

    Incidentally while they were not created to reduce versioning problems they can certainly help with them.

    0 讨论(0)
  • 2021-01-11 19:12

    Well there wasn't any language integrated mechanism syntax for it, but you can achieve interfaces in C++ with pure virtual classes.

    class IFoo
    {
    public:
      void Bar() =0;
      void Bar2() =0;
    };
    
    class Concrete : public IFoo
    {
    public:
      void Bar() { ... }
      void Bar2() { ... }
    }
    
    0 讨论(0)
  • 2021-01-11 19:12

    Java, perhaps?

    http://java.sun.com/docs/books/tutorial/java/concepts/interface.html

    0 讨论(0)
  • 2021-01-11 19:13

    They existed in C++, but they were known as virtual base classes, which consisted only of pure virtual functions. This is where the "I-" prefix for interfaces came from -- to differentiate between virtual base classes from abstract base classes.

    0 讨论(0)
  • 2021-01-11 19:14

    Interfaces are pretty old, and have been around for quite a while.

    Early (mid to late late 1970's) non-object oriented languages such as Modula and Euclid used constructs called "modules" to specify the interfaces between components. Components would then communicate with each other via explicit importing and exporting modules. Interfaces in C# are object oriented evolutions of that same concept.

    Interfaces in C# directly extend from the concept of interfaces in C++ (and Java), where they were used as part of COM for describing object-oriented component interfaces.

    EDIT: In doing a small amount of research, the earliest language I could find with an explicit "interface" keyword was Modula-3, a derivitive of Modula created around 1986.

    0 讨论(0)
  • 2021-01-11 19:14

    I think the basic idea is "multiple inheritance". So the idea came from C++.

    0 讨论(0)
提交回复
热议问题