Is programming against interfaces in Java the same concept as using header files in C/C++?

前端 未结 7 1359
失恋的感觉
失恋的感觉 2021-02-07 08:02

The java code I\'m working on at the moment has often a structure like

file Controller.java:

interface Controller {...}

file Controller

7条回答
  •  迷失自我
    2021-02-07 08:56

    No. In C++, files (headers) are not the same as classes.

    Programming against interfaces as in Java can be done in C++, too, by programming against abstract base classes.

    However, the Java term of "interface" is quite restricted. Basically, any function declaration is an interface:

    void call_me(int times); 
    

    As are, of course, classes and other types.

    In C++, you group such things in headers, so an interface can consist of one header. However, it might just as well consist of multiple headers.

提交回复
热议问题