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
520
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
680
Celeryの紹介と本番運用のTips
hankehly
0
1.7k
ChatGPTを活用した 便利ツールの紹介
hankehly
1
1.4k
Efficient Energy Analytics with Airflow, Spark, and MLFlow
hankehly
0
430
Deferrable Operators入門
hankehly
0
810
【初心者/ハンズオン】Dockerコンテナの基礎知識
hankehly
0
620
Compositeパターン: オブジェクトの階層関係をエレガントに表現する方法
hankehly
0
370
10/29 Airflowの基礎を学ぶハンズオンワークショップ
hankehly
0
340
システム/データ品質保証のための Airflow 活用法
hankehly
0
700
Other Decks in Technology
See All in Technology
自律型 AI をセキュアに実装!Gemini と MIG で作る動的コード実行環境
recruitengineers
PRO
1
230
子育てエンジニアの可処分時間が減っても成長を諦めない戦い方
sudoakiy
4
3.8k
1万名の社員が使う認証基盤で どう信頼性を担保するか?
kairim0
0
210
IoTデバイスを繋げるプロトコルMatterをAndroidで使用する方法
harutiro
0
120
自主式軟體工廠
philipz
0
240
検証フェーズはAIの回答を判断するための学習機会
toru_kubota
2
520
AI時代のAPI開発を加速する品質ガードレール / API Quality Guardrails in the AI Era
yokawasa
0
160
AgentCoreで実践するハーネスエンジニアリング
yakumo
1
290
LLM機能を自作して分かるSnowflake Cortex AIの強み
nayuts
0
320
メルペイ 会計システム概要と歴史
mewuto
0
190
AIがコードを書く時代に、エンジニアは何で自分の価値を証明するのか / In an era where AI writes code how do engineers prove their value
carta_engineering
0
260
FactoryBotアンチパターン / factory_bot anti-patterns
toshimaru
0
140
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
37
4k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
350
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
250
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
860
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
970
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
720
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
400
The Invisible Side of Design
smashingmag
301
52k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
580
Google's AI Overviews - The New Search
badams
0
1.6k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
260
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株式会社 ご清聴ありがとうございます