SlideShare une entreprise Scribd logo
1  sur  71
Télécharger pour lire hors ligne
Minimal Cake Pattern in Swift
kbkz.tech #11
吉村 優
https://twitter.com/_yyu_
http://qiita.com/yyu
https://github.com/y-yu
September 16, 2016
(Commit ID: 5acb721)
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 1 / 21
自己紹介
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 2 / 21
自己紹介
Scala 書 仕事 従事
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 2 / 21
自己紹介
Scala 書 仕事 従事
趣味 LATEX 暗号技術
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 2 / 21
自己紹介
Scala 書 仕事 従事
趣味 LATEX 暗号技術
Swift 最近 初心者
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 2 / 21
DI(Dependency Injection) ?
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 3 / 21
DI(Dependency Injection) ?
Dependency Injection ?
“ Dependency 実際 使
Injection Dependency 使
渡
Scala 最適 Dependency Injection 方法 考察 [1]
”
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 3 / 21
DI
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
DI
“
Scala 最適 Dependency Injection 方法 考察 [1]
”
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
DI
“ 同士 疎結合
Scala 最適 Dependency Injection 方法 考察 [1]
”
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
DI
“ 同士 疎結合
動作 可能
Scala 最適 Dependency Injection 方法 考察 [1]
”
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
DI
“ 同士 疎結合
動作 可能
依存 化
可能
Scala 最適 Dependency Injection 方法 考察 [1]
”
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
DI
“ 同士 疎結合
動作 可能
依存 化
可能
Scala 最適 Dependency Injection 方法 考察 [1]
”
?
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
Swift 代表的 DI手法
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
Swift 代表的 DI手法
Swift 代表的 DI 手法
“ Dependency Injection in Swift 2.x[2]
”
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
Swift 代表的 DI手法
Swift 代表的 DI 手法
“ Swinject 用 動的 DI
Dependency Injection in Swift 2.x[2]
”
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
Swift 代表的 DI手法
Swift 代表的 DI 手法
“ Swinject 用 動的 DI
Cake Pattern 用 静的 DI
Dependency Injection in Swift 2.x[2]
”
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
Swift 代表的 DI手法
Swift 代表的 DI 手法
“ Swinject 用 動的 DI
Cake Pattern 用 静的 DI
Dependency Injection in Swift 2.x[2]
”
以外 ?
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
Swift 代表的 DI手法
Swift 代表的 DI 手法
“ Swinject 用 動的 DI
Cake Pattern 用 静的 DI
Dependency Injection in Swift 2.x[2]
”
以外 ?
Cake Pattern 仲間 “Minimal Cake Pattern” 紹介!
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
Example
機能 作
∗ 使 関数
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
Example
機能 作
HashPasswordService
鍵付 関数∗ 化 機能
∗ 使 関数
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
Example
機能 作
HashPasswordService
鍵付 関数∗ 化 機能
必要 機能
∗ 使 関数
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
Example
機能 作
HashPasswordService
鍵付 関数∗ 化 機能
必要 機能
設定 読 込 機能
∗ 使 関数
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
Example
機能 作
HashPasswordService
鍵付 関数∗ 化 機能
必要 機能
設定 読 込 機能
化 機能
∗ 使 関数
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
Example
機能 作
HashPasswordService
鍵付 関数∗ 化 機能
必要 機能
設定 読 込 機能
化 機能
設定 読 込 ?
∗ 使 関数
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
Example
考
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
Example
考
微妙
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
Example
考
微妙
設定 保存
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
Example
考
微妙
設定 保存
一方、 時 読 込
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
Example
考
微妙
設定 保存
一方、 時 読 込
IO 失敗 失敗 !
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
Example
考
微妙
設定 保存
一方、 時 読 込
IO 失敗 失敗 !
本実装 設定 読 込 、 時
使
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
Example
考
微妙
設定 保存
一方、 時 読 込
IO 失敗 失敗 !
本実装 設定 読 込 、 時
使
二 実装 必要
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
設定 読 込 機能
設定 読 込 部分
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 8 / 21
設定 読 込 機能
設定 読 込 部分
1 ReadConfigService 作成
protocol ReadConfigService {
var configName: String { get }
func readSalt() -> String
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 8 / 21
設定 読 込 機能
設定 読 込 部分
1 ReadConfigService 作成
protocol ReadConfigService {
var configName: String { get }
func readSalt() -> String
}
2 実装 投入
extension ReadConfigService {
private func readFile() -> Optional<String> {
if {
return Optional.Some( 中 身)
} else {
return Optional.None
}
}
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 8 / 21
設定 読 込 機能
4 実装 ReadConfigServiceImpl 作成
class ReadConfigServiceImpl: ReadConfigService {
let configName: String
init(_ str: String) {
configName = str
}
func readSalt() -> String {
// 本 当 … …
return readFile()!
}
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 9 / 21
設定 読 込 機能
4 実装 ReadConfigServiceImpl 作成
class ReadConfigServiceImpl: ReadConfigService {
let configName: String
init(_ str: String) {
configName = str
}
func readSalt() -> String {
// 本 当 … …
return readFile()!
}
}
設定 引数 受 取 、
読 込
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 9 / 21
設定 読 込 機能
5 実装 ReadConfigServiceMockImpl 作成
class ReadConfigServiceMockImpl: ReadConfigService {
var configName: String = "dummy"
let dummySalt: String
init(_ salt: String) {
dummySalt = salt
}
func readSalt() -> String {
return dummySalt
}
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 10 / 21
設定 読 込 機能
5 実装 ReadConfigServiceMockImpl 作成
class ReadConfigServiceMockImpl: ReadConfigService {
var configName: String = "dummy"
let dummySalt: String
init(_ salt: String) {
dummySalt = salt
}
func readSalt() -> String {
return dummySalt
}
}
設定 、 引
数 与 値 必 返
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 10 / 21
設定 読 込 機能
5 実装 ReadConfigServiceMockImpl 作成
class ReadConfigServiceMockImpl: ReadConfigService {
var configName: String = "dummy"
let dummySalt: String
init(_ salt: String) {
dummySalt = salt
}
func readSalt() -> String {
return dummySalt
}
}
設定 、 引
数 与 値 必 返
、設定 !
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 10 / 21
設定 読 込 機能
6 依存 示 UsesReadConfigService
作成
protocol UsesReadConfigService {
var readConfigService: ReadConfigService { get }
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 11 / 21
設定 読 込 機能
6 依存 示 UsesReadConfigService
作成
protocol UsesReadConfigService {
var readConfigService: ReadConfigService { get }
}
使
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 11 / 21
化 機能
次 、 化 部分 作成
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 12 / 21
化 機能
次 、 化 部分 作成
1 作成
protocol HashPasswordService: UsesReadConfigService {
func hashBySha1(password: String) -> String
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 12 / 21
化 機能
次 、 化 部分 作成
1 作成
protocol HashPasswordService: UsesReadConfigService {
func hashBySha1(password: String) -> String
}
ReadConfigService 依存 示
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 12 / 21
化 機能
次 、 化 部分 作成
1 作成
protocol HashPasswordService: UsesReadConfigService {
func hashBySha1(password: String) -> String
}
ReadConfigService 依存 示
2 実装 投入
extension HashPasswordService {
func hashBySha1(password: String) -> String {
let data = password + readConfigService.readSalt()
//
return SHA1(data).toString()
}
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 12 / 21
化 機能
1 実装 作成
class HashPasswordSerivceImpl: HashPasswordService {
let readConfigService: ReadConfigService
init(_ configFile: String) {
readConfigService = ReadConfigServiceImpl(configFile)
}
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 13 / 21
化 機能
1 実装 作成
class HashPasswordSerivceImpl: HashPasswordService {
let readConfigService: ReadConfigService
init(_ configFile: String) {
readConfigService = ReadConfigServiceImpl(configFile)
}
}
ReadConfigService 実装 DI
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 13 / 21
化 機能
1 実装 作成
class HashPasswordSerivceImpl: HashPasswordService {
let readConfigService: ReadConfigService
init(_ configFile: String) {
readConfigService = ReadConfigServiceImpl(configFile)
}
}
ReadConfigService 実装 DI
2 実装 作成
class HashPasswordServiceTestImpl: HashPasswordService {
var readConfigService: ReadConfigService =
ReadConfigServiceMockImpl("dummySalt")
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 13 / 21
化 機能
1 実装 作成
class HashPasswordSerivceImpl: HashPasswordService {
let readConfigService: ReadConfigService
init(_ configFile: String) {
readConfigService = ReadConfigServiceImpl(configFile)
}
}
ReadConfigService 実装 DI
2 実装 作成
class HashPasswordServiceTestImpl: HashPasswordService {
var readConfigService: ReadConfigService =
ReadConfigServiceMockImpl("dummySalt")
}
ReadConfigService 実装 DI
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 13 / 21
化 機能
11 作成
class HashPasswordServiceMockImpl: HashPasswordService {
var readConfigService: ReadConfigService =
ReadConfigServiceMockImpl("dummySalt")
func hashBySha1(password: String) -> String {
return password + "_dummySalt"
}
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 14 / 21
化 機能
11 作成
class HashPasswordServiceMockImpl: HashPasswordService {
var readConfigService: ReadConfigService =
ReadConfigServiceMockImpl("dummySalt")
func hashBySha1(password: String) -> String {
return password + "_dummySalt"
}
}
値 計算
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 14 / 21
化 機能
11 作成
class HashPasswordServiceMockImpl: HashPasswordService {
var readConfigService: ReadConfigService =
ReadConfigServiceMockImpl("dummySalt")
func hashBySha1(password: String) -> String {
return password + "_dummySalt"
}
}
値 計算
実装 変更 、依存
落
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 14 / 21
作成 HashPasswordService 作
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 15 / 21
作成 HashPasswordService 作
import XCTest
@testable import MCPExample
class HashPasswordServiceTest: XCTestCase {
// 用 実 装 使
var sut: HashPasswordService = HashPasswordServiceTestImpl()
func testHashBySha1() {
XCTAssert(sut.hashBySha1("hoge") == "
ba5b31f489676c1545a9f175867274c8c21b8f8b")
}
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 15 / 21
作成 HashPasswordService 作
import XCTest
@testable import MCPExample
class HashPasswordServiceTest: XCTestCase {
// 用 実 装 使
var sut: HashPasswordService = HashPasswordServiceTestImpl()
func testHashBySha1() {
XCTAssert(sut.hashBySha1("hoge") == "
ba5b31f489676c1545a9f175867274c8c21b8f8b")
}
}
設定 読 !
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 15 / 21
DI 漏
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 16 / 21
DI 漏
次 DI 忘
class HashPasswordServiceNgImpl: HashPasswordService {
func hashBySha1(password: String) -> String {
return "ng"
}
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 16 / 21
DI 漏
次 DI 忘
class HashPasswordServiceNgImpl: HashPasswordService {
func hashBySha1(password: String) -> String {
return "ng"
}
}
HashPasswordService.swift:41:7: Type 'HashPasswordServiceNgImpl'
does not conform to protocol 'UsesReadConfigService'
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 16 / 21
DI 漏
次 DI 忘
class HashPasswordServiceNgImpl: HashPasswordService {
func hashBySha1(password: String) -> String {
return "ng"
}
}
HashPasswordService.swift:41:7: Type 'HashPasswordServiceNgImpl'
does not conform to protocol 'UsesReadConfigService'
実行前 DI 漏 検出!
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 16 / 21
DI 漏
次 DI 忘
class HashPasswordServiceNgImpl: HashPasswordService {
func hashBySha1(password: String) -> String {
return "ng"
}
}
HashPasswordService.swift:41:7: Type 'HashPasswordServiceNgImpl'
does not conform to protocol 'UsesReadConfigService'
実行前 DI 漏 検出!
依存 増 効果的!
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 16 / 21
DI 漏
次 依存 増 、DI 漏
protocol CreateUserService:
UsesSessionService,
UsesUserRepository,
UsesClock,
UsesApplicationLogger,
UsesUserConfig,
UsesRandomGenerator {
func create(user: User) -> Future<Session>
}
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 17 / 21
DI 漏
次 依存 増 、DI 漏
protocol CreateUserService:
UsesSessionService,
UsesUserRepository,
UsesClock,
UsesApplicationLogger,
UsesUserConfig,
UsesRandomGenerator {
func create(user: User) -> Future<Session>
}
大 起動 大変!
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 17 / 21
DI 漏
次 依存 増 、DI 漏
protocol CreateUserService:
UsesSessionService,
UsesUserRepository,
UsesClock,
UsesApplicationLogger,
UsesUserConfig,
UsesRandomGenerator {
func create(user: User) -> Future<Session>
}
大 起動 大変!
起動 DI 漏 検出 便利!
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 17 / 21
Minimal Cake Pattern
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 18 / 21
Minimal Cake Pattern
静的 、DI 漏 検出
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 18 / 21
Minimal Cake Pattern
静的 、DI 漏 検出
DI 特別 必要
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 18 / 21
Minimal Cake Pattern
静的 、DI 漏 検出
DI 特別 必要
普通 Cake Pattern 比
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 18 / 21
目次
1 自己紹介
2 Dependency Injection ?
3 DI
4 Swift 代表的 DI 手法
5 Example
設定 読 込 機能
化 機能
DI 漏
6
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 19 / 21
参考文献
[1] 結城清太郎.
Scala 最適 dependency injection 方法 考察
~ 生産性 高 ~,
2015.
[2] 人間.
Dependency injection in swift 2.x, 2016.
[3] 吉村優.
Swift minimal cake pattern, 2016.
[4] Takashi Tayama.
Minimal cake pattern 作法, 2015.
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 20 / 21
Thank you for listening!
Any question?
吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 21 / 21

Contenu connexe

Similaire à Minimal Cake Pattern in Swift

Vagrant を Web開発環境に使う
Vagrant を Web開発環境に使うVagrant を Web開発環境に使う
Vagrant を Web開発環境に使うMasashi Shinbara
 
Knockout を用いた Firefox OS アプリケーションの開発
Knockout を用いた Firefox OS アプリケーションの開発Knockout を用いた Firefox OS アプリケーションの開発
Knockout を用いた Firefox OS アプリケーションの開発Kentaro Iizuka
 
リテラルと型の続きの話 #__swift__
リテラルと型の続きの話 #__swift__リテラルと型の続きの話 #__swift__
リテラルと型の続きの話 #__swift__Tomohiro Kumagai
 
MessagePack RPC によるドキドキ非同期通信 @関ジャバ 2012年度8月
MessagePack RPC によるドキドキ非同期通信 @関ジャバ 2012年度8月MessagePack RPC によるドキドキ非同期通信 @関ジャバ 2012年度8月
MessagePack RPC によるドキドキ非同期通信 @関ジャバ 2012年度8月Takashi Someda
 
OpenGLプログラミング
OpenGLプログラミングOpenGLプログラミング
OpenGLプログラミング幸雄 村上
 
アメブロ2016 アメブロフロント刷新にみる ひかりとつらみ
アメブロ2016 アメブロフロント刷新にみる ひかりとつらみアメブロ2016 アメブロフロント刷新にみる ひかりとつらみ
アメブロ2016 アメブロフロント刷新にみる ひかりとつらみKazunari Hara
 
9/16 Tokyo Apache Drill Meetup - drill vs sparksql
9/16 Tokyo Apache Drill Meetup - drill vs sparksql9/16 Tokyo Apache Drill Meetup - drill vs sparksql
9/16 Tokyo Apache Drill Meetup - drill vs sparksqlMitsutoshi Kiuchi
 
YAPC::Kansai 2017 - macOSネイティブアプリ作成におけるPerlの活用
YAPC::Kansai 2017 - macOSネイティブアプリ作成におけるPerlの活用YAPC::Kansai 2017 - macOSネイティブアプリ作成におけるPerlの活用
YAPC::Kansai 2017 - macOSネイティブアプリ作成におけるPerlの活用純生 野田
 
Swift 3 その基本ルールを眺める #cswift
Swift 3 その基本ルールを眺める #cswiftSwift 3 その基本ルールを眺める #cswift
Swift 3 その基本ルールを眺める #cswiftTomohiro Kumagai
 
Head toward Java 15 and Java 16
Head toward Java 15 and Java 16Head toward Java 15 and Java 16
Head toward Java 15 and Java 16Yuji Kubota
 
Java8 Stream APIとApache SparkとAsakusa Frameworkの類似点・相違点
Java8 Stream APIとApache SparkとAsakusa Frameworkの類似点・相違点Java8 Stream APIとApache SparkとAsakusa Frameworkの類似点・相違点
Java8 Stream APIとApache SparkとAsakusa Frameworkの類似点・相違点hishidama
 
Spark Streamingを使ってみた ~Twitterリアルタイムトレンドランキング~
Spark Streamingを使ってみた ~Twitterリアルタイムトレンドランキング~Spark Streamingを使ってみた ~Twitterリアルタイムトレンドランキング~
Spark Streamingを使ってみた ~Twitterリアルタイムトレンドランキング~sugiyama koki
 
Head toward Java 16 (Night Seminar Edition)
Head toward Java 16 (Night Seminar Edition)Head toward Java 16 (Night Seminar Edition)
Head toward Java 16 (Night Seminar Edition)Yuji Kubota
 
Scotty を利用した "ゆるふわ" Web サービス作成
Scotty を利用した "ゆるふわ" Web サービス作成Scotty を利用した "ゆるふわ" Web サービス作成
Scotty を利用した "ゆるふわ" Web サービス作成krdlab
 

Similaire à Minimal Cake Pattern in Swift (18)

Vagrant を Web開発環境に使う
Vagrant を Web開発環境に使うVagrant を Web開発環境に使う
Vagrant を Web開発環境に使う
 
Knockout を用いた Firefox OS アプリケーションの開発
Knockout を用いた Firefox OS アプリケーションの開発Knockout を用いた Firefox OS アプリケーションの開発
Knockout を用いた Firefox OS アプリケーションの開発
 
Ansible2.0と実用例
Ansible2.0と実用例Ansible2.0と実用例
Ansible2.0と実用例
 
リテラルと型の続きの話 #__swift__
リテラルと型の続きの話 #__swift__リテラルと型の続きの話 #__swift__
リテラルと型の続きの話 #__swift__
 
Boost sg msgpack
Boost sg msgpackBoost sg msgpack
Boost sg msgpack
 
MessagePack RPC によるドキドキ非同期通信 @関ジャバ 2012年度8月
MessagePack RPC によるドキドキ非同期通信 @関ジャバ 2012年度8月MessagePack RPC によるドキドキ非同期通信 @関ジャバ 2012年度8月
MessagePack RPC によるドキドキ非同期通信 @関ジャバ 2012年度8月
 
OpenGLプログラミング
OpenGLプログラミングOpenGLプログラミング
OpenGLプログラミング
 
アメブロ2016 アメブロフロント刷新にみる ひかりとつらみ
アメブロ2016 アメブロフロント刷新にみる ひかりとつらみアメブロ2016 アメブロフロント刷新にみる ひかりとつらみ
アメブロ2016 アメブロフロント刷新にみる ひかりとつらみ
 
9/16 Tokyo Apache Drill Meetup - drill vs sparksql
9/16 Tokyo Apache Drill Meetup - drill vs sparksql9/16 Tokyo Apache Drill Meetup - drill vs sparksql
9/16 Tokyo Apache Drill Meetup - drill vs sparksql
 
Rx java x retrofit
Rx java x retrofitRx java x retrofit
Rx java x retrofit
 
YAPC::Kansai 2017 - macOSネイティブアプリ作成におけるPerlの活用
YAPC::Kansai 2017 - macOSネイティブアプリ作成におけるPerlの活用YAPC::Kansai 2017 - macOSネイティブアプリ作成におけるPerlの活用
YAPC::Kansai 2017 - macOSネイティブアプリ作成におけるPerlの活用
 
Swift 3 その基本ルールを眺める #cswift
Swift 3 その基本ルールを眺める #cswiftSwift 3 その基本ルールを眺める #cswift
Swift 3 その基本ルールを眺める #cswift
 
Head toward Java 15 and Java 16
Head toward Java 15 and Java 16Head toward Java 15 and Java 16
Head toward Java 15 and Java 16
 
Java8 Stream APIとApache SparkとAsakusa Frameworkの類似点・相違点
Java8 Stream APIとApache SparkとAsakusa Frameworkの類似点・相違点Java8 Stream APIとApache SparkとAsakusa Frameworkの類似点・相違点
Java8 Stream APIとApache SparkとAsakusa Frameworkの類似点・相違点
 
Spark Streamingを使ってみた ~Twitterリアルタイムトレンドランキング~
Spark Streamingを使ってみた ~Twitterリアルタイムトレンドランキング~Spark Streamingを使ってみた ~Twitterリアルタイムトレンドランキング~
Spark Streamingを使ってみた ~Twitterリアルタイムトレンドランキング~
 
Head toward Java 16 (Night Seminar Edition)
Head toward Java 16 (Night Seminar Edition)Head toward Java 16 (Night Seminar Edition)
Head toward Java 16 (Night Seminar Edition)
 
scala-kaigi1-sbt
scala-kaigi1-sbtscala-kaigi1-sbt
scala-kaigi1-sbt
 
Scotty を利用した "ゆるふわ" Web サービス作成
Scotty を利用した "ゆるふわ" Web サービス作成Scotty を利用した "ゆるふわ" Web サービス作成
Scotty を利用した "ゆるふわ" Web サービス作成
 

Plus de Hikaru Yoshimura

Fujitask meets Extensible Effects
Fujitask meets Extensible EffectsFujitask meets Extensible Effects
Fujitask meets Extensible EffectsHikaru Yoshimura
 
公平なガチャ(tsukuba.lua)
公平なガチャ(tsukuba.lua)公平なガチャ(tsukuba.lua)
公平なガチャ(tsukuba.lua)Hikaru Yoshimura
 
Mental Jinroを支える暗号技術
Mental Jinroを支える暗号技術Mental Jinroを支える暗号技術
Mental Jinroを支える暗号技術Hikaru Yoshimura
 
Regular expressions à la carte
Regular expressions à la carteRegular expressions à la carte
Regular expressions à la carteHikaru Yoshimura
 

Plus de Hikaru Yoshimura (7)

Fujitask meets Extensible Effects
Fujitask meets Extensible EffectsFujitask meets Extensible Effects
Fujitask meets Extensible Effects
 
BitcoinでCTF
BitcoinでCTFBitcoinでCTF
BitcoinでCTF
 
公平なガチャ(tsukuba.lua)
公平なガチャ(tsukuba.lua)公平なガチャ(tsukuba.lua)
公平なガチャ(tsukuba.lua)
 
Extensible Exception
Extensible ExceptionExtensible Exception
Extensible Exception
 
Mental Jinroを支える暗号技術
Mental Jinroを支える暗号技術Mental Jinroを支える暗号技術
Mental Jinroを支える暗号技術
 
Regular expressions à la carte
Regular expressions à la carteRegular expressions à la carte
Regular expressions à la carte
 
Tagless Final DSL
Tagless Final DSLTagless Final DSL
Tagless Final DSL
 

Dernier

論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...Toru Tamaki
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Hiroshi Tomioka
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NTT DATA Technology & Innovation
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイスCRI Japan, Inc.
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Gamesatsushi061452
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video UnderstandingToru Tamaki
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルCRI Japan, Inc.
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)Hiroshi Tomioka
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 

Dernier (11)

論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 

Minimal Cake Pattern in Swift

  • 1. Minimal Cake Pattern in Swift kbkz.tech #11 吉村 優 https://twitter.com/_yyu_ http://qiita.com/yyu https://github.com/y-yu September 16, 2016 (Commit ID: 5acb721) 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 1 / 21
  • 2. 自己紹介 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 2 / 21
  • 3. 自己紹介 Scala 書 仕事 従事 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 2 / 21
  • 4. 自己紹介 Scala 書 仕事 従事 趣味 LATEX 暗号技術 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 2 / 21
  • 5. 自己紹介 Scala 書 仕事 従事 趣味 LATEX 暗号技術 Swift 最近 初心者 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 2 / 21
  • 6. DI(Dependency Injection) ? 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 3 / 21
  • 7. DI(Dependency Injection) ? Dependency Injection ? “ Dependency 実際 使 Injection Dependency 使 渡 Scala 最適 Dependency Injection 方法 考察 [1] ” 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 3 / 21
  • 8. DI 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
  • 9. DI “ Scala 最適 Dependency Injection 方法 考察 [1] ” 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
  • 10. DI “ 同士 疎結合 Scala 最適 Dependency Injection 方法 考察 [1] ” 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
  • 11. DI “ 同士 疎結合 動作 可能 Scala 最適 Dependency Injection 方法 考察 [1] ” 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
  • 12. DI “ 同士 疎結合 動作 可能 依存 化 可能 Scala 最適 Dependency Injection 方法 考察 [1] ” 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
  • 13. DI “ 同士 疎結合 動作 可能 依存 化 可能 Scala 最適 Dependency Injection 方法 考察 [1] ” ? 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 4 / 21
  • 14. Swift 代表的 DI手法 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
  • 15. Swift 代表的 DI手法 Swift 代表的 DI 手法 “ Dependency Injection in Swift 2.x[2] ” 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
  • 16. Swift 代表的 DI手法 Swift 代表的 DI 手法 “ Swinject 用 動的 DI Dependency Injection in Swift 2.x[2] ” 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
  • 17. Swift 代表的 DI手法 Swift 代表的 DI 手法 “ Swinject 用 動的 DI Cake Pattern 用 静的 DI Dependency Injection in Swift 2.x[2] ” 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
  • 18. Swift 代表的 DI手法 Swift 代表的 DI 手法 “ Swinject 用 動的 DI Cake Pattern 用 静的 DI Dependency Injection in Swift 2.x[2] ” 以外 ? 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
  • 19. Swift 代表的 DI手法 Swift 代表的 DI 手法 “ Swinject 用 動的 DI Cake Pattern 用 静的 DI Dependency Injection in Swift 2.x[2] ” 以外 ? Cake Pattern 仲間 “Minimal Cake Pattern” 紹介! 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 5 / 21
  • 20. Example 機能 作 ∗ 使 関数 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
  • 21. Example 機能 作 HashPasswordService 鍵付 関数∗ 化 機能 ∗ 使 関数 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
  • 22. Example 機能 作 HashPasswordService 鍵付 関数∗ 化 機能 必要 機能 ∗ 使 関数 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
  • 23. Example 機能 作 HashPasswordService 鍵付 関数∗ 化 機能 必要 機能 設定 読 込 機能 ∗ 使 関数 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
  • 24. Example 機能 作 HashPasswordService 鍵付 関数∗ 化 機能 必要 機能 設定 読 込 機能 化 機能 ∗ 使 関数 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
  • 25. Example 機能 作 HashPasswordService 鍵付 関数∗ 化 機能 必要 機能 設定 読 込 機能 化 機能 設定 読 込 ? ∗ 使 関数 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 6 / 21
  • 26. Example 考 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
  • 27. Example 考 微妙 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
  • 28. Example 考 微妙 設定 保存 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
  • 29. Example 考 微妙 設定 保存 一方、 時 読 込 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
  • 30. Example 考 微妙 設定 保存 一方、 時 読 込 IO 失敗 失敗 ! 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
  • 31. Example 考 微妙 設定 保存 一方、 時 読 込 IO 失敗 失敗 ! 本実装 設定 読 込 、 時 使 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
  • 32. Example 考 微妙 設定 保存 一方、 時 読 込 IO 失敗 失敗 ! 本実装 設定 読 込 、 時 使 二 実装 必要 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 7 / 21
  • 33. 設定 読 込 機能 設定 読 込 部分 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 8 / 21
  • 34. 設定 読 込 機能 設定 読 込 部分 1 ReadConfigService 作成 protocol ReadConfigService { var configName: String { get } func readSalt() -> String } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 8 / 21
  • 35. 設定 読 込 機能 設定 読 込 部分 1 ReadConfigService 作成 protocol ReadConfigService { var configName: String { get } func readSalt() -> String } 2 実装 投入 extension ReadConfigService { private func readFile() -> Optional<String> { if { return Optional.Some( 中 身) } else { return Optional.None } } } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 8 / 21
  • 36. 設定 読 込 機能 4 実装 ReadConfigServiceImpl 作成 class ReadConfigServiceImpl: ReadConfigService { let configName: String init(_ str: String) { configName = str } func readSalt() -> String { // 本 当 … … return readFile()! } } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 9 / 21
  • 37. 設定 読 込 機能 4 実装 ReadConfigServiceImpl 作成 class ReadConfigServiceImpl: ReadConfigService { let configName: String init(_ str: String) { configName = str } func readSalt() -> String { // 本 当 … … return readFile()! } } 設定 引数 受 取 、 読 込 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 9 / 21
  • 38. 設定 読 込 機能 5 実装 ReadConfigServiceMockImpl 作成 class ReadConfigServiceMockImpl: ReadConfigService { var configName: String = "dummy" let dummySalt: String init(_ salt: String) { dummySalt = salt } func readSalt() -> String { return dummySalt } } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 10 / 21
  • 39. 設定 読 込 機能 5 実装 ReadConfigServiceMockImpl 作成 class ReadConfigServiceMockImpl: ReadConfigService { var configName: String = "dummy" let dummySalt: String init(_ salt: String) { dummySalt = salt } func readSalt() -> String { return dummySalt } } 設定 、 引 数 与 値 必 返 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 10 / 21
  • 40. 設定 読 込 機能 5 実装 ReadConfigServiceMockImpl 作成 class ReadConfigServiceMockImpl: ReadConfigService { var configName: String = "dummy" let dummySalt: String init(_ salt: String) { dummySalt = salt } func readSalt() -> String { return dummySalt } } 設定 、 引 数 与 値 必 返 、設定 ! 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 10 / 21
  • 41. 設定 読 込 機能 6 依存 示 UsesReadConfigService 作成 protocol UsesReadConfigService { var readConfigService: ReadConfigService { get } } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 11 / 21
  • 42. 設定 読 込 機能 6 依存 示 UsesReadConfigService 作成 protocol UsesReadConfigService { var readConfigService: ReadConfigService { get } } 使 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 11 / 21
  • 43. 化 機能 次 、 化 部分 作成 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 12 / 21
  • 44. 化 機能 次 、 化 部分 作成 1 作成 protocol HashPasswordService: UsesReadConfigService { func hashBySha1(password: String) -> String } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 12 / 21
  • 45. 化 機能 次 、 化 部分 作成 1 作成 protocol HashPasswordService: UsesReadConfigService { func hashBySha1(password: String) -> String } ReadConfigService 依存 示 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 12 / 21
  • 46. 化 機能 次 、 化 部分 作成 1 作成 protocol HashPasswordService: UsesReadConfigService { func hashBySha1(password: String) -> String } ReadConfigService 依存 示 2 実装 投入 extension HashPasswordService { func hashBySha1(password: String) -> String { let data = password + readConfigService.readSalt() // return SHA1(data).toString() } } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 12 / 21
  • 47. 化 機能 1 実装 作成 class HashPasswordSerivceImpl: HashPasswordService { let readConfigService: ReadConfigService init(_ configFile: String) { readConfigService = ReadConfigServiceImpl(configFile) } } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 13 / 21
  • 48. 化 機能 1 実装 作成 class HashPasswordSerivceImpl: HashPasswordService { let readConfigService: ReadConfigService init(_ configFile: String) { readConfigService = ReadConfigServiceImpl(configFile) } } ReadConfigService 実装 DI 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 13 / 21
  • 49. 化 機能 1 実装 作成 class HashPasswordSerivceImpl: HashPasswordService { let readConfigService: ReadConfigService init(_ configFile: String) { readConfigService = ReadConfigServiceImpl(configFile) } } ReadConfigService 実装 DI 2 実装 作成 class HashPasswordServiceTestImpl: HashPasswordService { var readConfigService: ReadConfigService = ReadConfigServiceMockImpl("dummySalt") } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 13 / 21
  • 50. 化 機能 1 実装 作成 class HashPasswordSerivceImpl: HashPasswordService { let readConfigService: ReadConfigService init(_ configFile: String) { readConfigService = ReadConfigServiceImpl(configFile) } } ReadConfigService 実装 DI 2 実装 作成 class HashPasswordServiceTestImpl: HashPasswordService { var readConfigService: ReadConfigService = ReadConfigServiceMockImpl("dummySalt") } ReadConfigService 実装 DI 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 13 / 21
  • 51. 化 機能 11 作成 class HashPasswordServiceMockImpl: HashPasswordService { var readConfigService: ReadConfigService = ReadConfigServiceMockImpl("dummySalt") func hashBySha1(password: String) -> String { return password + "_dummySalt" } } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 14 / 21
  • 52. 化 機能 11 作成 class HashPasswordServiceMockImpl: HashPasswordService { var readConfigService: ReadConfigService = ReadConfigServiceMockImpl("dummySalt") func hashBySha1(password: String) -> String { return password + "_dummySalt" } } 値 計算 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 14 / 21
  • 53. 化 機能 11 作成 class HashPasswordServiceMockImpl: HashPasswordService { var readConfigService: ReadConfigService = ReadConfigServiceMockImpl("dummySalt") func hashBySha1(password: String) -> String { return password + "_dummySalt" } } 値 計算 実装 変更 、依存 落 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 14 / 21
  • 54. 作成 HashPasswordService 作 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 15 / 21
  • 55. 作成 HashPasswordService 作 import XCTest @testable import MCPExample class HashPasswordServiceTest: XCTestCase { // 用 実 装 使 var sut: HashPasswordService = HashPasswordServiceTestImpl() func testHashBySha1() { XCTAssert(sut.hashBySha1("hoge") == " ba5b31f489676c1545a9f175867274c8c21b8f8b") } } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 15 / 21
  • 56. 作成 HashPasswordService 作 import XCTest @testable import MCPExample class HashPasswordServiceTest: XCTestCase { // 用 実 装 使 var sut: HashPasswordService = HashPasswordServiceTestImpl() func testHashBySha1() { XCTAssert(sut.hashBySha1("hoge") == " ba5b31f489676c1545a9f175867274c8c21b8f8b") } } 設定 読 ! 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 15 / 21
  • 57. DI 漏 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 16 / 21
  • 58. DI 漏 次 DI 忘 class HashPasswordServiceNgImpl: HashPasswordService { func hashBySha1(password: String) -> String { return "ng" } } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 16 / 21
  • 59. DI 漏 次 DI 忘 class HashPasswordServiceNgImpl: HashPasswordService { func hashBySha1(password: String) -> String { return "ng" } } HashPasswordService.swift:41:7: Type 'HashPasswordServiceNgImpl' does not conform to protocol 'UsesReadConfigService' 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 16 / 21
  • 60. DI 漏 次 DI 忘 class HashPasswordServiceNgImpl: HashPasswordService { func hashBySha1(password: String) -> String { return "ng" } } HashPasswordService.swift:41:7: Type 'HashPasswordServiceNgImpl' does not conform to protocol 'UsesReadConfigService' 実行前 DI 漏 検出! 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 16 / 21
  • 61. DI 漏 次 DI 忘 class HashPasswordServiceNgImpl: HashPasswordService { func hashBySha1(password: String) -> String { return "ng" } } HashPasswordService.swift:41:7: Type 'HashPasswordServiceNgImpl' does not conform to protocol 'UsesReadConfigService' 実行前 DI 漏 検出! 依存 増 効果的! 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 16 / 21
  • 62. DI 漏 次 依存 増 、DI 漏 protocol CreateUserService: UsesSessionService, UsesUserRepository, UsesClock, UsesApplicationLogger, UsesUserConfig, UsesRandomGenerator { func create(user: User) -> Future<Session> } 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 17 / 21
  • 63. DI 漏 次 依存 増 、DI 漏 protocol CreateUserService: UsesSessionService, UsesUserRepository, UsesClock, UsesApplicationLogger, UsesUserConfig, UsesRandomGenerator { func create(user: User) -> Future<Session> } 大 起動 大変! 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 17 / 21
  • 64. DI 漏 次 依存 増 、DI 漏 protocol CreateUserService: UsesSessionService, UsesUserRepository, UsesClock, UsesApplicationLogger, UsesUserConfig, UsesRandomGenerator { func create(user: User) -> Future<Session> } 大 起動 大変! 起動 DI 漏 検出 便利! 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 17 / 21
  • 65. Minimal Cake Pattern 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 18 / 21
  • 66. Minimal Cake Pattern 静的 、DI 漏 検出 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 18 / 21
  • 67. Minimal Cake Pattern 静的 、DI 漏 検出 DI 特別 必要 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 18 / 21
  • 68. Minimal Cake Pattern 静的 、DI 漏 検出 DI 特別 必要 普通 Cake Pattern 比 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 18 / 21
  • 69. 目次 1 自己紹介 2 Dependency Injection ? 3 DI 4 Swift 代表的 DI 手法 5 Example 設定 読 込 機能 化 機能 DI 漏 6 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 19 / 21
  • 70. 参考文献 [1] 結城清太郎. Scala 最適 dependency injection 方法 考察 ~ 生産性 高 ~, 2015. [2] 人間. Dependency injection in swift 2.x, 2016. [3] 吉村優. Swift minimal cake pattern, 2016. [4] Takashi Tayama. Minimal cake pattern 作法, 2015. 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 20 / 21
  • 71. Thank you for listening! Any question? 吉村 優 (@_yyu_) Minimal Cake Pattern in Swift September 16, 2016 21 / 21