插件和框架的区别
框架和插件有什么区别?即哪些因素决定何时使用插件和框架?
What is the difference between frameworks and plug-ins? i.e Which factors decide when to use plug-ins and frameworks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
框架提供功能,必须编写程序才能使用这些功能;插件扩展了其他东西的功能,通常不需要重写现有程序即可使用。您可以很好地使用两者,通过提供基本界面的框架和向界面添加功能的插件。
例如:
PAM
PAM 库是一个框架; PAM 模块是插件。您可以编辑
/etc/pam.conf
或/etc/pam.d/*
来使用插件,而不是重新编译使用 PAM 库的代码。但是旧的包需要重写以使用PAM框架,而不是直接访问各种系统文件。NSS
类似地,NSS 由一个框架和一组在该框架内提供功能的插件组成。在这种情况下,大多数东西不需要重新编译,因为旧框架(
libc
的getpwent
和类似函数)提供的接口对于新框架来说已经足够了一。 (例外是依赖影子密码文件的任何东西,或者对于更旧的程序,依赖常规密码文件中的密码。)配置涉及编辑/etc/nsswitch.conf
而不是修改程序。 p>赛勒斯SASL
与上面类似,SASL库是一个框架,但身份验证机制是插件。配置主要是通过 SASL lib 目录中的文件进行的,尽管某些程序也使用一个接口,允许将其嵌入到这些程序自己的配置文件中;同样,无论哪种情况,都不需要重新编译来添加、更改、启用或禁用机制。
在 Mac OS X 上,服务是作为插件实现的;相应的框架内置于标准框架中。
Windows 有类似的框架和插件,但我对 Windows 的了解还不够,无法指出任何好的例子。
无论如何,一般规则是使用框架为程序提供访问功能的接口,并使用框架内的插件来提供或扩展其功能。
Frameworks provide functionality, which programs must be written to use; plugins extend something else's functionality, usually in a way that doesn't require rewriting existing programs to use. You may well use both, with a framework that provides a basic interface and plugins that add functionality to the interface.
Examples of this are:
PAM
The PAM library is a framework; PAM modules are plugins. You edit
/etc/pam.conf
or/etc/pam.d/*
to use the plugins, instead of recompiling code that uses the PAM library. But older packages need to be rewritten to use the PAM framework instead of directly accessing various system files.NSS
Similarly, NSS consists of a framework and a set of plugins that provide functionality within that framework. In this case, most things don't need to be recompiled because the interfaces provided by an older framework (
libc
'sgetpwent
and similar functions) were mostly sufficient for the new one. (The exception being anything that relied on the shadow password file, or for even older programs the password in the regular password file.) Configuration involves editing/etc/nsswitch.conf
insyead of modifying programs.Cyrus SASL
Similar to the above, the SASL library is a framework, but the authentication mechanisms are plugins. Configuration is mostly by files in the SASL lib directory, although there is also an interface used by some programs which allows it to be embedded in those programs' own configuration files; again, in either case it doesn't require recompiling to add, change, enable or disable mechanisms.
On Mac OS X, services are implemented as plugins; the corresponding framework is built into the standard frameworks.
There are similar frameworks and plugins for Windows, but I don't really know enough about Windows to point to any good examples.
In any case, the general rule is that you use a framework to provide interfaces for programs to access functionality, and use plugins within a framework to provide or extend its functionality.