库如何与其他代码交互?
我一直在阅读有关封装的内容,并且不断看到有关如何更改类的隐私或添加以前没有的 getter 和 setter 的评论,这些评论可能会“破坏使用您的库的人的代码”。我实在不明白这一点。我在编程方面非常缺乏经验,我的理解是,你将一个库下载到你的计算机上,它包含在你正在编写的程序的文件中,所以如果原作者在库的副本中更改了某些内容,它就不会不影响你的副本。这是错误的吗?例如,图书馆是否更像是一个网站,您的计算机通过互联网连接到该网站,并且原作者可以更新,以便他们对其所做的更改可以影响您的代码的工作方式?
I've been reading about encapsulation and keep seeing comments about how changing the privacy of a class or adding getters and setters where there were none before can 'break the code' of people who use your library. I don't really understand this. I'm very inexperienced in programming, and my understanding is that you download a library onto your computer and it's included in the files of the program you're writing, so if the original author changed something in THEIR COPY of the library, it wouldn't affect your copy. Is this wrong? For example, is a library more like a website that your computer connects to through the internet and the original author can update, so that changes they make to it can affect how your code works?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
软件不断变化,因此我们必须有一种方法来跟踪不同的版本 - 因此软件版本。当您下载一个库以在自己的程序中使用时,您(通常,就像使用依赖项管理工具一样)最终会下载该库的一个非常特定的版本。
如果库作者要更改使用它的界面,那么使用该库的开发人员在下载包含这些更改的版本时也必须更改他们使用它的方式。否则,它会破坏任何遵循过时接口的代码。
只要库作者遵循正确的版本控制程序,例如在新的主要版本中包括重大更改,并且这些更改提高了库接口的清晰度而不牺牲其他属性,那么这个论点就毫无意义。开发人员可以继续使用旧版本,也可以更新代码以兼容新版本。
除了可能在资源不足的情况下,嵌入式系统可以使用所有可用的优化,例如直接访问对象/结构属性而不是通过函数。
Software is constantly changing, so we must have a way to keep track of the different versions - hence software versions. When you download a library to use in your own program, you (usually, like with a dependency management tool) end up downloading a very specific version of that library.
If a library author was to change the interface to use it, developers using that library would also have to change how they use it when they download the version with those changes. Otherwise, it would break any code that follows an outdated interface.
As long as a library author follows proper versioning procedures, for instance including breaking changes in a new major version, and the changes improve the clarity of the library's interfaces without sacrificing other properties, then the argument is moot. Developers can either continue using the old version or update their code to be compatible with the new version.
Except for maybe in low resource, embedded systems that can use all optimizations available, like accessing object/structure properties directly rather than through a function.
图书馆:
说明
你的要求
你问
快乐编码
希望这对您有所帮助,祝您编码愉快。
Libraries:
Explanation
Your ask
You ask
Happy Coding
Hope this was helpful, happy coding.