Share
Embed
Transcript
22 slides
-
本発表で伝えたいこと • DI (Dependency Injection) は「依存性の注入」(2004) より「依存物の注 入」と訳したほうが適切 • 2000年の前後10年、dependencyという言葉の意味合いが変わっている
• よって、「依存性の注入」は単なる誤訳である以上に歴史の産物と言える -
速習:DIとは? “The basic idea of the Dependency Injection is to
have a separate object, an assembler, that populates a field in the lister class with an appropriate implementation for the finder interface[.]” Martin Fowler, “Inversion of Control Containers and the Dependency Injection Pattern” (https://www.martinfowler.com/articles/injection.html, 2004) -
名詞としてのdependency 1. 不可算名詞 依存(の状態) 2. 可算名詞 属国,保護領 研究社『新英和中辞典』 これから話すこと • オブジェクト指向モデリングの文脈における① •
DIにおける②(ただし主従関係が逆転している) • DI関連文献でのdependencyは①と②の使い方が混ざっている -
オブジェクト指向モデリングの文脈 “[Object] Y might be a part of [object] X,
but Y might also be visible to other objects in different ways. In Smalltalk, this kind of visibility usually represents a dependency between two objects.” Grady Booch, Object-Oriented Analysis and Design (Addison-Wesley, 1994 [1990]), 140. -
ファウラーの「DI論文」以降の用例 “Inversion of Control has already been referred to as
Dependency Injection. The basic principle is that beans define their dependencies (i.e. the other objects they work with) only through constructor arguments, arguments to a factory method, or properties which are set on the object instance after it has been constructed or returned from a factory method. Then, it is the job of the container to actually inject those dependencies when it creates the bean. “Spring Reference Documentation” (https://docs.spring.io/spring-framework/docs/1.1.1/spring-reference.pdf, 2004, 11). -
ファウラーの「DI論文」以降の用例 「Inversion of ControlはDependency Injectionという名称ですでに言及されて いる。〔IoC/DIの〕基本的な原則は、beanが自身のdependencies(すなわち、 利用する他のオブジェクト) をコンストラクタの引数やファクトリーメソッドの引 数、またはオブジェクト・インスタンスに付与されたプロパティ〔中略〕経由のみで 定義することにある。その後、それらのdependenciesを注入することはコンテナ
の仕事である」 ※以降、Spring Frameworkのリファレンスはこの文章を踏襲している (https://docs.spring.io/spring-framework/reference/core/beans/dependenci es/factory-collaborators.html) -
dependencyの「依存性」という訳語 • Smalltalk-80関連だと遅くとも1990年代前半には例が見られる ◦ 「MVCはMの変化をVに暗黙的に伝えるための仕組みとして依存性 (dependency) を利用している。〔中略〕Mはdependentsというメッセージを 自分に送ることにより、自分と依存関係にあるVを〔Objectクラスの変数であ る〕依存性の辞書から得る」 桑原
修二, 藤村 茂, 富田 昭司, 1992,「MVC の拡張, MVCG とそれに基づく UIMS, Talkie の実装」『コンピュータソフトウェア』9(1): 28頁 →「依存性」という訳と「依存物」「依存関係」という意味合いが共存する環境は 1990年代の時点で存在していた -
2004~2005年にdependency=依存性が定着した? • 2004年1月: ファウラーの論文 • 2004年3月: 角谷信太郎の私訳版 ◦ 「依存性注入」(2009年2月に「依存オブジェクト注入」に訂正) •
2004年夏以降: ブログ記事やSpring関連のWikiに「依存性注入」 ◦ Spring PadのDependency Injectionページ(2004年7月更新。同年11月時 点のアーカイブ) • 2004年7月: マーティン『アジャイルソフトウェア開発の奥義』邦訳 ◦ Dependency Inversion Principle=「依存関係逆転の原則』 ◦ 2004年12月~2005年1月の読書会の議事録に「依存性逆転」という文言 (次スライドに続く) -
2004~2005年にdependency=依存性が定着した? • 2005年7月: Spring: A Developer’s Guide (2005) の邦訳版 ◦
原文にあったdependencyの訳は「依存性」に統一されている • 2006年11月: Wikipediaに「依存性の注入」記事が新規作成 ◦ 2022年9月に「依存オブジェクトの注入」という補足が追記 ※2004~2005年の『Java World』と『Java Press』の記事も補足なしの 「依存性注入」ばかり(櫻庭さん調べ) -
おまけ:「依存性はdependenceでしょ?」議論 • 『日本物理学会誌』1963年18巻10号の議論 • 「dependencyは事物、dependenceは状態や性質では?」 • 学会で英語圏の学者たちに聞いてみた ◦ 「依存性質はdependenceでしょ」 ◦
「dependencyは事物のこと。属国とか」 • ただし、やがて英語圏でもdependencyは「依存性質」も表すことに ◦ オブジェクト指向界隈然り ◦ 国際関係然り(例:dependency on Russian oil) -
まとめ • オブジェクト指向界隈において、dependencyは当初「依存状態にある関係 性」の意味合いが強かった • 2000年代中盤以降、依存関係にあるオブジェクトの実装という文脈から、 dependencyで「依存しているもの」を表すケースが生まれた • dependencyの用例の変遷を把握しておくと、DIの説明がしやすい Object
X Object Y Object Object Object Object X Object Object Object