什么是头部背后的原因是什么? [英] What's the rationale behind headers?

查看:124
本文介绍了什么是头部背后的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白有一个头的点;这似乎违反了DRY原则!是(可)包含在标题中的所有信息在执行。

I don't quite understand the point of having a header; it seems to violate the DRY principle! All the information in a header is (can be) contained in the implementation.

推荐答案

它简化了编译过程。当你想单独编译单元,你需要的东西来描述将被链接到零件,而无需导入所有其他文件的全部内容。

It simplifies the compilation process. When you want to compile units independently, you need something to describe the parts that will be linked to without having to import the entirety of all the other files.

它还允许code躲藏。人们可以分发头允许他人使用该功能,而无需分发的执行。

It also allows for code hiding. One can distribute a header to allow others to use the functionality without having to distribute the implementation.

最后,可以鼓励接口从实施分离

Finally, it can encourage the separation of interface from implementation.

他们不解决这些问题的唯一途径,但30年前,他们是一个很好的一个。我们可能不会使用头文件为今天的语言,但他们并没有在2009年发明的。

They are not the only way to solve these problems, but 30 years ago they were a good one. We probably wouldn't use header files for a language today, but they weren't invented in 2009.

这篇关于什么是头部背后的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆