SlideShare a Scribd company logo
Java EEにおける
Dependency
Injectionの基礎
2021-08-05
蓮沼 賢志 (HASUNUMA Kenji)
k.hasunuma@coppermine.jp
復習:オブジェクト指向プログラミングとは?
• オブジェクト=データ(フィールド)と操作(メソッド)の集合体
• オブジェクトの定義=クラス、オブジェクトの実体=インスタンス
• オブジェクト間のメッセージ・パッシング(=メソッド呼び出し)でデータ処理(=プログラム)
を記述・実行する
• オブジェクト指向プログラミングの3要素 ※上記に比べればさほど重要ではない
• カプセル化 (Encapsulation)
• 継承 (Inheritance)
• 多態性 (Polymorphism)
オブジェクトと依存性について
• “A は B に依存している”
→ A と B は密結合である
• a が b を直接生成できないケー
スがある
• a と b の生存期間が異なる
例: a はHTTPリクエスト毎に生成
されるが、b は複数のリクエスト
にまたがって生存する
• b がネットワーク上のオブジェク
トである(分散コンポーネント)
• 解決案
→ A と B を疎結合にする
疎結合の実現方法①:JNDIルックアップ
1. A は B を知らない
→ b にアクセスできない
2. A は JNDI から B を取得する
→ b へのアクセス手段 b’ を
得られる
3. B として b’ を呼び出す
→ 間接的に b を呼び出す
• 事前に B を JNDI へ登録してお
く必要がある
• A は JNDI から B を明示的に取
得する必要がある
疎結合の実現方法②:Dependency Injection (DI)
1. m は A に B を設定する
→ A は m から B へのアクセ
ス手段 b’ を得ている
2. B として b’ を呼び出す
→間接的に b を呼び出す
• m は A に対して
B への依存性 (Dependency) を
注入 (Inject) している
• b’ の取得方法がJNDIルック
アップと逆になっている
→制御の反転 (Inverse of
Control)
Ad

Recommended

Neural relation extraction for knowledge base enrichment introduced by Yoshia...
Neural relation extraction for knowledge base enrichment introduced by Yoshia...
Ace12358
 
An object graph visualizer for PHP - print_o
An object graph visualizer for PHP - print_o
Akihito Koriyama
 
[Tokyor08] Rによるデータサイエンス 第2部 第3章 対応分析
[Tokyor08] Rによるデータサイエンス 第2部 第3章 対応分析
Yohei Sato
 
Recurrent Neural Network
Recurrent Neural Network
KozoChikai
 
多変量解析
多変量解析
Yoshihiro_Handa
 
今さら聞けないDiとspring
今さら聞けないDiとspring
土岐 孝平
 
JJUG 11月ナイトセミナー CDIをはじめよう
JJUG 11月ナイトセミナー CDIをはじめよう
Norito Agetsuma
 
Spring勉強会
Spring勉強会
gaaupp
 
DI(依存性注入)について
DI(依存性注入)について
Yui Ito
 
Dependency inversion
Dependency inversion
TakashiSuzuki32
 
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
耕二 阿部
 
20160526 依存関係逆転の原則
20160526 依存関係逆転の原則
bonjin6770 Kurosawa
 
Dependency Injectionとは
Dependency Injectionとは
Hidenori Doi
 
Jakarta REST in depth
Jakarta REST in depth
Kenji HASUNUMA
 
Life of our small product
Life of our small product
Kenji HASUNUMA
 
Jakarta EE : The First Parts
Jakarta EE : The First Parts
Kenji HASUNUMA
 
Overviewing Admin Console
Overviewing Admin Console
Kenji HASUNUMA
 
How to adapt MicroProfile API for Generic Web Applications
How to adapt MicroProfile API for Generic Web Applications
Kenji HASUNUMA
 
Introduction to MicroProfile Metrics
Introduction to MicroProfile Metrics
Kenji HASUNUMA
 
Introduction to JCA and MDB
Introduction to JCA and MDB
Kenji HASUNUMA
 
Virtualization Fundamental
Virtualization Fundamental
Kenji HASUNUMA
 
JLS myths
JLS myths
Kenji HASUNUMA
 
Introduction to Date and Time API 4
Introduction to Date and Time API 4
Kenji HASUNUMA
 
Fundamental Java
Fundamental Java
Kenji HASUNUMA
 
Collections Framework Begineers guide 2
Collections Framework Begineers guide 2
Kenji HASUNUMA
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3
Kenji HASUNUMA
 
Introduction to JavaFX Dialogs
Introduction to JavaFX Dialogs
Kenji HASUNUMA
 
Brand new Date and Time API
Brand new Date and Time API
Kenji HASUNUMA
 
Introduction to Date and Time API 2
Introduction to Date and Time API 2
Kenji HASUNUMA
 

More Related Content

Similar to oop-in-javaee (6)

Spring勉強会
Spring勉強会
gaaupp
 
DI(依存性注入)について
DI(依存性注入)について
Yui Ito
 
Dependency inversion
Dependency inversion
TakashiSuzuki32
 
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
耕二 阿部
 
20160526 依存関係逆転の原則
20160526 依存関係逆転の原則
bonjin6770 Kurosawa
 
Dependency Injectionとは
Dependency Injectionとは
Hidenori Doi
 
Spring勉強会
Spring勉強会
gaaupp
 
DI(依存性注入)について
DI(依存性注入)について
Yui Ito
 
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
耕二 阿部
 
20160526 依存関係逆転の原則
20160526 依存関係逆転の原則
bonjin6770 Kurosawa
 
Dependency Injectionとは
Dependency Injectionとは
Hidenori Doi
 

More from Kenji HASUNUMA (17)

Jakarta REST in depth
Jakarta REST in depth
Kenji HASUNUMA
 
Life of our small product
Life of our small product
Kenji HASUNUMA
 
Jakarta EE : The First Parts
Jakarta EE : The First Parts
Kenji HASUNUMA
 
Overviewing Admin Console
Overviewing Admin Console
Kenji HASUNUMA
 
How to adapt MicroProfile API for Generic Web Applications
How to adapt MicroProfile API for Generic Web Applications
Kenji HASUNUMA
 
Introduction to MicroProfile Metrics
Introduction to MicroProfile Metrics
Kenji HASUNUMA
 
Introduction to JCA and MDB
Introduction to JCA and MDB
Kenji HASUNUMA
 
Virtualization Fundamental
Virtualization Fundamental
Kenji HASUNUMA
 
JLS myths
JLS myths
Kenji HASUNUMA
 
Introduction to Date and Time API 4
Introduction to Date and Time API 4
Kenji HASUNUMA
 
Fundamental Java
Fundamental Java
Kenji HASUNUMA
 
Collections Framework Begineers guide 2
Collections Framework Begineers guide 2
Kenji HASUNUMA
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3
Kenji HASUNUMA
 
Introduction to JavaFX Dialogs
Introduction to JavaFX Dialogs
Kenji HASUNUMA
 
Brand new Date and Time API
Brand new Date and Time API
Kenji HASUNUMA
 
Introduction to Date and Time API 2
Introduction to Date and Time API 2
Kenji HASUNUMA
 
Introduction to Data and Time API
Introduction to Data and Time API
Kenji HASUNUMA
 
Life of our small product
Life of our small product
Kenji HASUNUMA
 
Jakarta EE : The First Parts
Jakarta EE : The First Parts
Kenji HASUNUMA
 
Overviewing Admin Console
Overviewing Admin Console
Kenji HASUNUMA
 
How to adapt MicroProfile API for Generic Web Applications
How to adapt MicroProfile API for Generic Web Applications
Kenji HASUNUMA
 
Introduction to MicroProfile Metrics
Introduction to MicroProfile Metrics
Kenji HASUNUMA
 
Introduction to JCA and MDB
Introduction to JCA and MDB
Kenji HASUNUMA
 
Virtualization Fundamental
Virtualization Fundamental
Kenji HASUNUMA
 
Introduction to Date and Time API 4
Introduction to Date and Time API 4
Kenji HASUNUMA
 
Collections Framework Begineers guide 2
Collections Framework Begineers guide 2
Kenji HASUNUMA
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3
Kenji HASUNUMA
 
Introduction to JavaFX Dialogs
Introduction to JavaFX Dialogs
Kenji HASUNUMA
 
Brand new Date and Time API
Brand new Date and Time API
Kenji HASUNUMA
 
Introduction to Date and Time API 2
Introduction to Date and Time API 2
Kenji HASUNUMA
 
Introduction to Data and Time API
Introduction to Data and Time API
Kenji HASUNUMA
 
Ad

oop-in-javaee