如何创建一个灵活的插件架构? [英] How To Create a Flexible Plug-In Architecture?

查看:137
本文介绍了如何创建一个灵活的插件架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的开发工作重复的主题一直使用或创建一个内部插件架构。我看到它接近许多方面 - 配置文件(XML,.conf文件,等等),继承框架,数据库信息,图书馆等。根据我的经验:

A repeating theme in my development work has been the use of or creation of an in-house plug-in architecture. I've seen it approached many ways - configuration files (XML, .conf, and so on), inheritance frameworks, database information, libraries, and others. In my experience:


  • 数据库未存储配置信息的好地方,尤其是混在一起的数据

  • 与继承层次尝试,这需要对插件的知识将在codeD,这意味着插件架构是不是所有的动态

  • 配置文件的工作以及提供简单的信息,但不能处理更复杂的行为

  • 库似乎运作良好,但依赖单向的,必须精心打造。

当我征求我已经,我也期待向社会征求意见工作的各种架构学习。你如何实现一个坚实的插件架构?什么是你最失败(或者你所见过的最失败的)?你会怎么做,如果你要实现一个新的插件架构?你曾经使用过什么SDK或开源项目具有良好的建筑最好的例子?

As I seek to learn from the various architectures I've worked with, I'm also looking to the community for suggestions. How have you implemented a solid plug-in architecture? What was your worst failure (or the worst failure you've seen)? What would you do if you were going to implement a new plug-in architecture? What SDK or open source project that you've worked with has the best example of a good architecture?

举几个例子,我一直在寻找我自己的:

A few examples I've been finding on my own:


  • Perl的<一个href=\"http://search.cpan.org/~simonw/Module-Pluggable-3.9/lib/Module/Pluggable.pm\">Module::Plugable和国际奥委会以在Perl依赖注入

  • 依赖注入的各种弹簧框架(Java,.NET,Python的)。

  • 质疑,提供对Java(包括的Service提供者接口的)

  • 质疑以C ++指向<一个href=\"http://www.drdobbs.com/cpp/204202899;jsessionid=2P021EF4CUUAFQE1GHPSKH4ATMY32JVN?cid=RSSfeed%255FDDJ%255FCpp\">Dr.多布斯文章

  • 质疑关于ASP为特定插件的想法。 NET MVC

  • Perl's Module::Plugable and IOC for dependency injection in Perl
  • The various Spring frameworks (Java, .NET, Python) for dependency injection.
  • An SO question with a list for Java (including Service Provider Interfaces)
  • An SO question for C++ pointing to a Dr. Dobbs article
  • An SO question regarding a specific plugin idea for ASP.NET MVC

这些例子似乎发挥各种语言的优势。是一个很好的插件架构不必拘泥于语言?它是最好用的工具来创建一个插件架构,还是做它自己以下车型?

These examples seem to play to various language strengths. Is a good plugin architecture necessarily tied to the language? Is it best to use tools to create a plugin architecture, or to do it on one's own following models?

推荐答案

这是不是一个的答案的多达一堆潜在有用的言论/例子。

This is not an answer as much as a bunch of potentially useful remarks/examples.


  • 让你的应用程序扩展是揭露它的内部作为脚本语言写的所有顶级的东西,在这种语言的一个有效途径。这使得它非常修改和实践面向未来的(如果你的原语精心挑选和实施)。这种事情的成功是Emacs的。我preFER这对日食的风格插件系统,因为如果我想扩展功能,我没有学习API和编写/编译一个单独的插件。我可以写在当前缓冲区本身就是一个3线片断,评价和使用它。非常光滑的学习曲线,非常满意的结果。

  • One effective way to make your application extensible is to expose its internals as a scripting language and write all the top level stuff in that language. This makes it quite modifiable and practically future proof (if your primitives are well chosen and implemented). A success story of this kind of thing is Emacs. I prefer this to the eclipse style plugin system because if I want to extend functionality, I don't have to learn the API and write/compile a separate plugin. I can write a 3 line snippet in the current buffer itself, evaluate it and use it. Very smooth learning curve and very pleasing results.

我已经延长了一点一个应用是 Trac的。它在这种情况下意味着任务委托给广告扩展点模块组件体系结构。然后,您可以实施将融入这些点并改变流量等组成。这就像上面Kalkie的建议一点点。

One application which I've extended a little is Trac. It has a component architecture which in this situation means that tasks are delegated to modules that advertise extension points. You can then implement other components which would fit into these points and change the flow. It's a little like Kalkie's suggestion above.

另外一个是好是 py.test 。它遵循最好的API是没有API的理念,在被称为在每个级别挂钩纯粹依赖。您可以根据约定命名文件/功能可覆盖这些挂钩并改变行为。您可以在网站上看到插件列表,看看如何迅速/轻松地就可以实现。

Another one that's good is py.test. It follows the "best API is no API" philosophy and relies purely on hooks being called at every level. You can override these hooks in files/functions named according to a convention and alter the behaviour. You can see the list of plugins on the site to see how quickly/easily they can be implemented.

几个基本点。


  • 尝试,让您的不可扩展/非用户修改的内核尽可能小。委派一切你可以到一个更高的层,使可扩展性增加。越少到核心改正那么错误的选择时。

  • 相关上面的一点是,你不应该让你的项目在一开始的方向太多的决定。实施所需的最小的子集,然后开始编写插件。

  • 如果您是一个嵌入的脚本语言,以确保它是一个完整的在其中你可以编写一般的程序,而不是一个玩具语言的只为您的应用程序的。

  • 减少样板尽可能多的,你可以。不要用子类化,复杂的API,插件的注册和类似的东西打扰。尽量保持它的简单,这样它的容易的并不仅仅是可能的延伸。这将让你的插件API来使用更多,并鼓励最终用户编写插件。不仅仅是插件开发。 py.test做这口井。 Eclipse作为据我所知,<一个href=\"http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/core/runtime/Plugin.html\">does不的。

  • Try to keep your non-extensible/non-user-modifiable core as small as possible. Delegate everything you can to a higher layer so that the extensibility increases. Less stuff to correct in the core then in case of bad choices.
  • Related to the above point is that you shouldn't make too many decisions about the direction of your project at the outset. Implement the smallest needed subset and then start writing plugins.
  • If you are embedding a scripting language, make sure it's a full one in which you can write general programs and not a toy language just for your application.
  • Reduce boilerplate as much as you can. Don't bother with subclassing, complex APIs, plugin registration and stuff like that. Try to keep it simple so that it's easy and not just possible to extend. This will let your plugin API be used more and will encourage end users to write plugins. Not just plugin developers. py.test does this well. Eclipse as far as I know, does not.

这篇关于如何创建一个灵活的插件架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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