Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Interface and Implementation in different files? If you need this by design this is still very common to define the interface (or abstract class) in languages such as Java/C# in one file and hide the implementation(s) in other files. This does not require old and tricky header files. Commented Dec 30, 2012 at 14:49
  • eh? isn't that what I said - you define the interface and the class implementation in 2 files. Commented Dec 31, 2012 at 0:30
  • 2
    well, that does not require header files and that does not make header files any better. Yes, they are needed in languages with a legacy, but as a concept they are not needed to split interface/implementation in different files (actually, they make it worse). Commented Jan 1, 2013 at 12:54
  • @Petter I think you misunderstand, conceptually they are no different - a header exists to provide an interface in the C language, and though you are right - you can combine the 2 (as many do with header-only C code) its not a best practice that I've seen followed in many places. All C# devs I've seen split the interface away from the class, for example. Its a good practice to do this as then you can include the interface file in multiple other files without pollution. Now, if you think that this split is a best practice (it is) then the way to achieve it in C is by using header files. Commented Mar 24, 2014 at 15:55
  • If headers were actually useful for separating interface and implementation, things like PImpl wouldn't be needed to hide private components and decouple end-users from having to recompile against them. Instead, we get the worst of both worlds. Headers feign a quickly dismissed facade of separation, while opening a myriad of pitfalls, which require verbose boilerplate code if you need to work around them. Commented Sep 20, 2015 at 22:16