C++ Report: 模式的力量

--------------------------------------------------------------------------------
译者:封尘浪
若文章翻译的有不当之处,恳请阁下留言批评指出,封尘浪将不胜感激!你的批评鼓励是我继续探索的动力。

Pattern Forces
模式的力量

Douglas C. Schmidt
Editor-in-chief
C++ Report
September 1996

Every few years, with remarkable consistency, new concepts, methods, languages, and tools capture the fancy of software developers. For instance, over the past decade we've witnessed the rise (and sometimes the fall) of AI and expert systems, CASE tools, object-orientation, Smalltalk, C++, frameworks, components, CORBA, HTML, the WWW, Java, and recently patterns, which is the theme this month's C++ Report. In this editors corner, I'm going to explain why I think patterns are important to C++ programmers.

每过几年,软件开发者都能想象到引人注目的概念,方法,语言,和工具。举个例子,纵观过去的十年间(新东西有时增加有时减少)像,专家系统,CASE工具,object-orientation,Smalltalk,C++,framework(框架),components(组件),CORBA,HTML, the WWW, Java, 和现在的模式,那个是本月C++ Report的“主打曲”,作为编辑的我将要解释为什么我认为模式在C++编程中如此重要。


A pattern is a successful solution to a set of common problems that arise when building software [1]. In general, patterns aid the development of software by expressing the structure and collaboration of components to developers at a level higher than (1) source code or (2) object-oriented design models that focus on individual objects and classes.

 

开发软件的时候,一个模式能够成功的解决某一问题,通常,模式帮助开发人员站在更高的视野上利用结构和和协调的组件去开发,而不是去关注源代码,或利用对象和类去设计一个功能模块。

 

Patterns are particularly valuable to the C++ community because they help to clarify good solutions to forces that often befuddle novice C++ programmers. For instance, many frustrations with C++ arise from the language's focus on efficiency. A case in point is C++'s lack of a standard garbage collector, which can be inefficient in certain domains (such as real-time process control systems). However, knowledge of reference counting patterns (such as the "Counted Pointer" idiom [2,3]) can often serve the same role as an automatic garbage collector.

 

在C++社区模式很详细很有价值,因为它强大的作用能清晰的解决那些使新手程序员困惑的问题,举个例子,许多失败是由于C++语言的效率,比方说,C++标准缺少指针的垃圾回收机制,在这一方面他肯定无效率(像运行时进程控制系统),然而,了解了引用计数模式(像“计数指针”)就能作为一个垃圾回收机制来用。

 

Another common frustration with C++ is the undefined (and thus non-portable) order in which constructors for global objects in separate compilation units are initialized. This is particularly problematic for applications built using dynamic link libraries. In this case, one solution is to apply an object creational pattern like Singleton, which ensures a class only has one instance and provides a global point of access to this instance [1]. The Singleton pattern is often used to alleviate problems stemming from dependencies in the order in which globally accessible objects are initialized.

 

C++的另一个不足是没有定义(不方便的)指令,在构造函数为全局对象进行分块编译时已经初始化。对于应用程序使用动态链接库时这就是一个具体的问题,在这种情况下,一个解决方法是去请求对象创建一个单独的模式,确保类仅有一个实例提供全局指针来访此实例,这个独立的模式常被用来暂缓堵住问题,在其他全局访问对象是初始化时。

 

Capturing and documenting these types of memory management patterns is important for another reason -- it creates a body of literature that other C++ programmers can study and build upon to solve larger problems. For instance, in this issue, Ron White's feature article utilizes the Counted Pointer idiom to manage the low-level memory requirements of his "Unique Representation" pattern. Moreover, Ron's Unique Representation pattern also builds upon the Singleton pattern to ensure that there exists in memory only one copy of each unique object of a class.

 

捕获和文件编制这些类型在内存管理模式中非常重要,这是一个理由--创建一部文学作品,当解决大问题的时候其他的C++程序员能够学习和使用,举个例子,在这个问题上Ron White's的文章利用计数指针方式去解决低水准的内存需求在他的“唯一的表现”模式,与此同时Ron's 的唯一的表现模式也建立在独立模式确保每一个对象或类仅仅在内存中复制一次。

 

Patrice Gautier's article on "Extending the Visitor Pattern" is another example of extending existing patterns to produce new and better ways of solving recurring problems in complex C++ programs. Patrice explains how the use of C++ templates can overcome some common traps and pitfalls with the form of the Visitor pattern described in [1].

 

Patrice Gautier's 的文章 “再探模式”是另一个延续现存模式的例子,产生更好的新方发去解决复杂的C++编程问题,Patrice阐述了怎样使用C++模版克服一些常见圈套和陷阱和在访问模式中发现他们。

 

Ironically, this month's "Pattern Hatching" column by John Vlissides also discusses the Visitor pattern. One of the themes in John's column is that design tradeoffs (such as time vs. space) often motivate the use of one group of patterns rather than another. John explains how the structural complexity of the Observer pattern (which is ubiquitous in C++ GUI frameworks like MFC and Interviews) can be alleviated by using the Visitor pattern, at the expense of some additional run-time overhead.

 

极具讽刺的,这个月的“模式孵化”系列中John Vlissides也讨论了访问模式,John系列中的一篇是设计tradeoffs(这个单词没多大把握)(比如 时间与空间的权衡)这经常激发一组又一组的模式,Join阐述了,怎样使用访问模式减少结构复杂度,(随处可见在C++图形用户界面框架像MFC呀Interviews等)当然这建立在花费运行时开销。

 

Dov Bulka's article on "Performance and C++: Separating Myth from Reality" focuses on another design tradeoff (flexibility vs. performance). His work focuses on C++ programming techniques for optimizing the efficiency of performance-sensitive software systems, in this case the communication subsystem in IBM's AIX operating system kernel.

 

Dov Bulka 的文章“C++性能:从现实中分离的神话"关注了另一个主题(还是没把握)(灵活性和性能),他的主要工作是利用C++编程技巧让性能敏感性系统达到性能和效率上的最优化。

 

Dov doesn't describe his techniques in a standard pattern form. However, his techniques certainly fit the definition of patterns since they are recurring solutions used to solve performance problems throughout the AIX communication subsystem. In the same vein, John Lakos' feature article on "Large-Scale C++ Software Design" focuses on effective techniques for structuring the physical hierarchy of software systems to improve testability, maintainability, and reuse. His work documents proven experience used at Mentor Graphics to build very large and complex CAD systems in C++.

 

Dov没有讲述他在标准模式中的技巧,但是,自从他们再次想方设法解决在AIX communication subsystem中遇到的问题后,他的技巧无疑适合定义模式。与此同时,John Lakos 的经典文章"大型C++软件开发”则关注结构化和参次化软件系统以此来提高测试效率,主要是因为他的工作是为使用C++建立的大型复杂CAD系统撰写文档。

 

The patterns covered in John's article address a more architectural level of abstraction than the other patterns in this issue, which focus more on C++ programming and design. Those of you interested in reading about patterns in other areas, such as organizational patterns, might check out Jim Coplien's chapter on "A Generative Development-Process Pattern Language" in the first Pattern Languages of Program Design book [4]. The second volume [5] of this series of books just came out, and it has some excellent patterns related to C++, such as Tom Cargill's pattern on "Localized Ownership: Managing Dynamic Objects in C++."

 

在这个问题上,以更高更抽象的视野超过了其他模式,基本涵盖了John的文章。关注C++程序的设计,这儿有你感兴趣的关于模式在其他领域的文章,像组织化的模式,可以点击Jim Coplien 的那章“一个有创造力的进程模式语言” 这是关于模式语言的第一本程序设计图书,第二个关于这个系列的书将要面世,它有一些用C++实现的卓越模式,比如Tom Cargill的模式"本地所有权:用C++管理动态对象".

 

This month's editors corner just barely scratches the surface of patterns and the patterns community. The Pattern Languages of Programming (PLoP) conference, which should be taking place as you read this issue in September, is an annual forum dedicated to improving the expression of patterns. In addition, there are workshops, tutorials, and papers on patterns at other object-oriented conferences (such as Object Expo, C++ World, OOPSLA, ECOOP, and COOTS).

 

这个月,编辑好不容易让模式浮出水面并找到一些模式社区,在九月份的杂志中关于模式语言编程会议(PLoP)将会有你感兴趣的东西,每年一次的讨论都致力于提高表现模式,除此之外,哪儿还有研讨会,教程,和一些其他的关于模式的书面文档,同时也关注其他会议(比如Object Expo, C++ World, OOPSLA, ECOOP, and COOTS).

 

Patterns succeed because you take the time to read, learn, use, and write them. I strongly encourage you to get involved in the patterns community. For starters, the World Wide Web URL http://st-www.cs.uiuc.edu/users/patterns contains a comprehensive on-line reference to pattern-related material.

 

要想学好模式,你得花时间去读,去学,去用, 去写,我极力推荐你去参加一些模式交流,作为起步,http://st-www.cs.uiuc.edu/users/patterns 包含许多模式方面的在线资料。

 

--------------------------------------------------------------------------------

 

References
1. Gamma et al, Design Patterns -- Elements of Reusable Object-Oriented Software, Addison Wesley, 1995.
2. Coplien, J. Advanced C++ Programming Styles and Idioms, Addison-Wesley, 1992.

3. F. Buschmann, R. Meunier, H. Rohnert, P. Sommerlad, and M. Stal, Pattern-Oriented Software Architecture - A System of Patterns. Wiley and Sons, 1996.

4. J. O. Coplien and D. C. Schmidt, eds., Pattern Languages of Program Design, Vol 1. Reading, MA: Addison-Wesley, 1995.

5. J. Vlissides, J. O. Coplien, and N. Kerth, eds., Pattern Languages of Program Design, Vol 2. Reading, MA: Addison-Wesley, 1996.

 

--------------------------------------------------------------------------------

Back to C++ Report Editorials home page.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值