我在5月25号的的blog:
如何思考Design Pattern?中,转载了Eric Gamma对于Design Pattern 的论述(这是
Artima Developer的总编 Bill Venners对Erich Gamma的采访中的
第一部分)。而第二部分中,Bill 和 Eric 则讨论了重用性的重要性 (importance of reusability)。
重用的最高境界是什么?我们创建一个非常高层的,面向具体应用的框架,然后只要做简单的客户化,并且重用这个框架中现有的设计。(“We thought the way to create software was to build high-level, domain-specific frameworks, and then you just customize them and reuse all the design that is codified into them. That was the reuse nirvana.”)但是,连Eric都意识到,这太理想化了,因为 “ I have learned that it's hard to create highly reusable frameworks.”
在谈到可重用的framework的时候,Eric提到了Eclipse:
“A good example of how I like to see reuse at work is Eclipse. It's built of components we call plug-ins. A plug-in bundles your code and there is a separate manifest where you define which other plug-ins you extend and which points of extension your plug-in offers. Plug-ins provide reusable code following explicit conventions to separate API from internal code. The Eclipse component model is simple and consistent too. It has this kernel characteristic. Eclipse has a small kernel, and everything is done the same way via extension points. The combination of a component model and the focus on APIs is one of the key ingredients of Eclipse. Controlled extensibility is another important one. (Eclipse是构构建在我们称之为plug-in的组件上面的。一个plug-in含有你的代码,而且详细定义了你从哪些其他的plug-in扩展而来,以及你的plug-in提供了哪些扩展点给别人使用。Plug-in提供了可重用的代码,而且遵循将API和内部的代码分离开。同时,Eclipse的组件模式简单而且一致。Eclipse只有一个很小的核心,所有其他的都市通过扩展点这种同样的方式来做的。Eclipse中的一个重要组成部分就是组件模型和面向API的方式的结合。另一个重要点则是受到控制的扩展性。)”
那么,什么又是Controlled extensibility呢?为什么要对扩展性进行控制呢?
“You can go and expose everything, and people can change anything. The original Smalltalks had some of this flavor. The problems start when the next version comes along. If you have exposed everything, you cannot change anything or you break all your clients. … Also when you study the Eclipse API you will find that we go further than just specifying which classes are published API. The Eclipse API also specifies whether a class is intended to be subclassed. (你可以把一切都公布出来,SmallTalk就是这样做的。但是,当下一个版本出来的时候,可能就会碰到问题。如果你公布了一切,那么你就不能做改动了,活着你可能会破坏你的客户端使用的东西….在Eclipse里面,我们不仅仅定义了哪些类是公开的API,我们处理得更深层次,我们甚至定义了哪些API是可以被扩展的,哪些不可以。”
Eric对于重用,定义了三个级别:最低一级,重用类(classes);最高一级,框架(framework);而中间一级,就是设计模式(Design Pattern)(“This is where I see patterns. Design patterns are both smaller and more abstract than frameworks. They're really a description about how a couple of classes can relate to each other and interact with each other. The level of reuse increases when you move from classes to patterns and finally frameworks. ”
Eric提到了一个有趣的现象。通常,我们拿到一个需求,会先做设计,做设计的时候,我们会使用设计模式(Design Pattern)。但是,使用XP (eXtreme Programming)方式的人不这样做,他们先写测试(“They write a test”)
那么,设计一个framework的时候,要注意什么呢?要避免frameworkitis. (“ Frameworks abstract and provide higher level default functionality. To do so the framework needs to be in control. This loss of control can lead to what is sometimes called frameworkitis. ”)
Frameworkitis就是说,一个framework想要做的东西太多,或者它并不是按照你设想的做的而你又不能去改动它。(“Frameworkitis is the disease that a framework wants to do too much for you or it does it in a way that you don't want but you can't change it.”)
而且,一个framework要做的比较小,因为,如果framework太大了,那么它可能就会做太多(可能会frameworkitis),而且,不容易学习,学习曲线太长,也不容易维护。
Eria的论述真是非常精彩,而且也解释了Eclipse的一些内部设计。一定要阅读全文
[Update] 感谢lxwde的中文翻译。我的中文翻译可能不完全准确。中文翻译,请参考Related Links中给出的lxwde的中文翻译链接。
Artima developer
访谈的第一部分
如何思考Design Pattern?
CSDN上的中文翻译
Email this store to a friend (send a short email with a subject to this story)
Subscribe to kukooBlog (subscribe kukooBlog's RSS feed)
Send me feedback on this story
Software,Design Pattern,Eclipse
Programming, Eclipse