Skip to main content
QUICK REVIEW

[论文解读] On the Interaction of Object-Oriented Design Patterns and Programming Languages

Gerald Baumgartner, Konstantin Läufer|arXiv (Cornell University)|May 31, 2019
Software Engineering Research参考文献 29被引用 27
一句话总结

本文识别出主流面向对象语言在实现常见设计模式时存在的缺陷,提出了一组正交的、通用的编程语言构造(如将子类型与继承分离、词法作用域闭包、多分派),以简化模式的实现。其核心贡献是建立一个框架,用这些构造来描述设计模式,从而实现更清晰、更可移植、更广泛适用的模式描述,适用于多种语言社区。

ABSTRACT

Design patterns are distilled from many real systems to catalog common programming practice. However, some object-oriented design patterns are distorted or overly complicated because of the lack of supporting programming language constructs or mechanisms. For this paper, we have analyzed several published design patterns looking for idiomatic ways of working around constraints of the implementation language. From this analysis, we lay a groundwork of general-purpose language constructs and mechanisms that, if provided by a statically typed, object-oriented language, would better support the implementation of design patterns and, transitively, benefit the construction of many real systems. In particular, our catalog of language constructs includes subtyping separate from inheritance, lexically scoped closure objects independent of classes, and multimethod dispatch. The proposed constructs and mechanisms are not radically new, but rather are adopted from a variety of languages and programming language research and combined in a new, orthogonal manner. We argue that by describing design patterns in terms of the proposed constructs and mechanisms, pattern descriptions become simpler and, therefore, accessible to a larger number of language communities. Constructs and mechanisms lacking in a particular language can be implemented using paradigmatic idioms.

研究动机与目标

  • 识别现有面向对象编程语言的局限性如何扭曲或复杂化广泛使用的设计模式的实现。
  • 分析真实世界的设计模式,提取因缺少语言特性而产生的共性惯用法。
  • 提出一组最小化、正交的编程语言构造与机制,以更好地支持设计模式的实现。
  • 倡导以这些通用构造来描述设计模式,以提升其在不同语言生态中的可访问性与可重用性。
  • 通过识别主流静态类型面向对象语言普遍缺失的关键特性(如结构子类型、闭包、多分派),为未来语言设计提供指导。

提出的方法

  • 分析已发表的设计模式(如单例模式、句柄-主体模式),识别由语言限制引发的重复性实现惯用法。
  • 识别语言的重复性缺陷,如缺乏垃圾回收、缺少一等闭包、对子类型和接口支持薄弱。
  • 提出一组正交的编程语言构造:将子类型与继承分离、词法作用域闭包对象、多分派。
  • 证明这些构造能够比当前语言惯用法更简洁地表达所有现有设计模式。
  • 论证缺失的构造可通过目标语言中的典型惯用法进行模拟,从而实现模式的可移植性。
  • 评估现有语言(如 C++、Java、ML、Modula-3)以展示其在支持关键模式需求方面的不足。

实验结果

研究问题

  • RQ1主流面向对象语言的局限性如何扭曲或复杂化常见设计模式的实现?
  • RQ2当前静态类型面向对象语言缺少哪些语言构造与机制,导致无法以简洁、惯用的方式实现设计模式?
  • RQ3能否定义一组最小化、正交的编程语言构造,使其能简化在多种编程语言中表达设计模式?
  • RQ4在多大程度上可以通过使用一组通用构造,使设计模式的描述独立于特定语言特性?
  • RQ5在实践中,如何通过已确立的编程惯用法来补偿某些语言特性缺失,同时不损失清晰性或正确性?

主要发现

  • C++ 缺乏垃圾回收机制,迫使开发者采用复杂的惯用法实现如句柄-主体模式和信封-信件模式,而这些模式在具有垃圾回收的语言中会更简单。
  • 在支持通过模块机制或一等对象实现单例的语言中,单例模式基本是冗余的,表明某些模式只是对缺失语言特性的变通实现。
  • 子类型可与继承清晰分离,这样做能增强两个机制本身,提升类型安全性和代码复用性。
  • 词法作用域闭包对象支持函数式与抽象数据类型编程风格,为基于类的封装提供更灵活的替代方案。
  • 多分派扩展了单分派机制,支持在多个参数上表达多态行为,显著提升表达能力。
  • 现有任何语言均不支持所提议构造的完整集合——尤其是结构子类型、闭包、接口与多分派的组合——使得此类语言在语言设计上具有重大进步意义。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。