Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Strategyパターン
Search
Hank Ehly
June 29, 2022
Technology
530
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Strategyパターン
https://qiita.com/hankehly
Hank Ehly
June 29, 2022
More Decks by Hank Ehly
See All by Hank Ehly
Fivetranでデータ移動を自動化する
hankehly
0
690
Celeryの紹介と本番運用のTips
hankehly
0
1.8k
ChatGPTを活用した 便利ツールの紹介
hankehly
1
1.4k
Efficient Energy Analytics with Airflow, Spark, and MLFlow
hankehly
0
440
Deferrable Operators入門
hankehly
0
820
【初心者/ハンズオン】Dockerコンテナの基礎知識
hankehly
0
630
Compositeパターン: オブジェクトの階層関係をエレガントに表現する方法
hankehly
0
380
10/29 Airflowの基礎を学ぶハンズオンワークショップ
hankehly
0
350
システム/データ品質保証のための Airflow 活用法
hankehly
0
710
Other Decks in Technology
See All in Technology
Metadata - Section 3 : Dublin Core Standard · DC
mohab1
0
110
SSFの現在地 ― CAEP/RISCからAI Identityへ
oidfj
0
250
JAWSコミュニティに 参加して1年経った結果
ssakita
0
110
現場を動かすAIエージェント#2_製造業現場でのAI活用から見た、ハマる罠と実践知
kintotechdev
2
200
Kiro Crew 入門 (手を離しても進む仕事) | 目指せ Kiro マスター 11
inariku
PRO
4
570
コードレビューをなくして見えたもの
henteko
0
140
自治体AIコンタクトセンター、何をどこに任せる?~Amazon Connect Customer +Amazon Bedrockの実践知~ / 20261107 Satoshi Torano
shift_evolve
PRO
1
100
AWSを利用する上で知っておきたい名前解決の話 2026
nagisa53
5
3.2k
続・ソフトウェアアーキテクトのための意思決定術: Decision Readiness, Revisited — When AI Changes the Economics of Software Architecture
snoozer05
PRO
9
2.7k
Lint の層を組み直した話
bengo4com
3
330
デザインレビューは自動化できるのか?─ Flutter × Figma で UI 品質保証を考える
techiro
2
820
In-Context Learning再入門。ICLの勾配降下的解釈の研究動向を追ってみる。
dai08srhg
1
730
Featured
See All Featured
Chasing Engaging Ingredients in Design
codingconduct
0
390
GraphQLとの向き合い方2022年版
quramy
50
15k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
680
Scaling GitHub
holman
464
140k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.7k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k
Everyday Curiosity
cassininazir
0
390
Game over? The fight for quality and originality in the time of robots
wayneb77
1
330
A designer walks into a library…
pauljervisheath
211
25k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Transcript
Strategyパターン 2022/06/29
自己紹介 • Hank Ehly (ハンク イーリー) • ENECHANGE株式会社 • qiita.com/hankehly
• connpass.com/user/hankehly • github.com/hankehly
アジェンダ • 概要 • いつ使うか • 構造 • コード例
概要 • 交換可能な「アルゴリズム」を作る • Strategyと呼ぶ • Strategyは「複数あるやり方の中の一つのやり方」 • 例)ファイルをアップロードする機能 ◦
S3 ◦ Google Cloud Storage ◦ ローカルファイルシステム Strategy
概要 • コンテキスト(Context)に Strategy を渡す • コンポジション • コンテキストが Strategy
に処理を委託する class Context: def __init__(self, strategy): self.strategy = strategy def operation(self): self.strategy.operation()
概要 • Strategy は、ランタイムで選択できる if url.startswith("s3://"): context = Context(strategy=S3()) elif
url.startswith("gs://"): context = Context(strategy=GoogleCloudStorage()) else: context = Context(strategy=LocalStorage()) • Contextの中身を修正せずに振る舞いを変えている • Contextを「拡張」している ◦ テスト修正 / デグレ確認が減る
いつ使うか 1. 関連しているアルゴリズムの「やること」が同じで「やり方」だけ違う Random Forest と Deep Learning 2. ディスク容量、実行時間、ネットワーク速度などの考慮
ネットワークが遅い時は、画像の画質を多少落として送信する 3. メソッドの振る舞いを if/else で分岐して実装している時 いくつかの「Strategy」に分ける
構造 • Strategy ◦ 共通のインターフェイス
構造 • Strategy ◦ 共通のインターフェイス • ConcreteStrategy ◦ Strategyの実装
構造 • Strategy ◦ 共通のインターフェイス • ConcreteStrategy ◦ Strategyの実装 •
Context ◦ Strategyを持つ/使用する
class Storage: def upload(self, data, path): pass class S3(Storage): def
upload(self, data, path): print("S3の {path} に {data} をアップロードする ") class Context: def __init__(self, storage: Storage): self.storage = storage def upload(self, data, path): self.storage.upload(data, path) context = Context(storage=S3()) context.upload(b"hello world", "s3://bucket/file.csv") コード例
class Storage: def upload(self, data, path): pass class S3(Storage): def
upload(self, data, path): print("S3の {path} に {data} をアップロードする ") class Context: def __init__(self, storage: Storage): self.storage = storage def upload(self, data, path): self.storage.upload(data, path) context = Context(storage=S3()) context.upload(b"hello world", "s3://bucket/file.csv") コード例
class Storage: def upload(self, data, path): pass class S3(Storage): def
upload(self, data, path): print("S3の {path} に {data} をアップロードする ") class Context: def __init__(self, storage: Storage): self.storage = storage def upload(self, data, path): self.storage.upload(data, path) context = Context(storage=S3()) context.upload(b"hello world", "s3://bucket/file.csv") コード例
コード例 class Storage: def upload(self, data, path): pass class S3(Storage):
def upload(self, data, path): print("S3の {path} に {data} をアップロードする") class Context: def __init__(self, storage: Storage): self.storage = storage def upload(self, data, path): self.storage.upload(data, path) context = Context(storage=S3()) context.upload(b"hello world", "s3://bucket/file.csv")
Qiita ENECHANGE株式会社 ご清聴ありがとうございます