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
【JavaScript】Strategy Patternっぽいのをちょい使いしてif分を駆逐する
Search
TomPenguin
October 26, 2022
Programming
230
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
【JavaScript】Strategy Patternっぽいのをちょい使いしてif分を駆逐する
TomPenguin
October 26, 2022
Transcript
14 slides
Strategy Pattern JavaScript っぽいのをちょい使いして if文を駆逐する TomPenguin karabiner. inc 2022/10/26
スライドを書いた人 元百貨店員。 Vue.js触りつつバックエンドにピボットし つつあるエンジニア。 仙台から福岡のシステム開発会社にフルリ モートで勤務。 TomPenguin tompenguin_ Work at
karabiner, inc
アジェンダ ① if文が増えがちな処理 ② Strategy Patternとは?
① if文が増えがちな処理 Processing that tends to increase if statements
種別ごとに返す値が違う ① if文が増えがちな処理 チケット料金の例) • 大人料金は3,000円 • 小人料金は1,000円 • ペア料金は5,000円
条件により返す値が違う ① if文が増えがちな処理 条件の識別子がkey、対応す る値がvalueのオブジェクト を定義する。 ちょい使いするとこう ♀ if文が無くなってスッキリ!
閾値ごとに返す値が違う ① if文が増えがちな処理 団体割引の例) • 30人の利用で2割引 • 10人の利用で1割引 • それら以下は割引なし
閾値ごとに返す値が違う ① if文が増えがちな処理 ♀ 閾値と値を対応づけした配列 を用意する。 ちょい使いするとこう if文が無くなってオシャレ!
② Strategy Patternとは? What’s Strategy Pattern
② Strategy Patternとは? これまでのスライドの雰囲気のように、 種別ごとに異なる振る舞いをさせたいと き、その詳細を隠蔽するためのデザイン パターンですが、、 参考:【TS】今さら聞けないストラテジパターン https://zenn.dev/nekoniki/articles/396ebc523930c196dc13
② Strategy Patternとは? 単に種別や条件の時返す値が違うとき そのままパターンを実装すると大袈裟に なってしまうので ちょい使いしよう💡
おわりに 大事なことはデザインパターン通りに 忠実に実装することではなく いかにスマートに目の前の課 題を解決するか💡 ということです。
おわりに デザインパターンなどの勉強している 時は頭が固くなってしまいがちですが そのパターンが解決しようとし ている課題の本質を理解し 柔軟にパターンを適用していき ましょう。
Strategy Pattern JavaScript っぽいのをちょい使いして if文を駆逐する TomPenguin karabiner. inc 2022/10/26
More Decks by TomPenguin
See All by TomPenguin
Domain Modelを共有していい感じにプロダクトを作る
tompenguin
0
380
【JavaScript】クロージャを理解して正しく使う
tompenguin
0
550
Git ゼンゼン ムズカシクナイ
tompenguin
0
580
あきらめる Atomic Design
tompenguin
5
780
Other Decks in Programming
See All in Programming
Spec-driven Development with AI
simas
PRO
0
2.3k
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
360
Crash Auto Pipelines
veronikapj
1
430
Beyond Chatbots: Agentic UI with Open Standards @W-JAX 2026, München
manfredsteyer
PRO
0
120
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
280
自宅サーバはどこまで再現できるのか - Proxmox VE上のVM環境をIaCとバックアップで戻してみた
youto
0
430
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
16
9.4k
テストだけで見つかる? Rubyでつくるメソッド発掘器
izawa
0
140
AI-Powered Domain-Driven Design
ziobrando
0
470
Claude Codeのおかげでやりたいことがやれるようになったんだよォー!
sms_tech
0
160
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
150
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
270
Featured
See All Featured
The Limits of Empathy - UXLibs8
cassininazir
2
790
How GitHub (no longer) Works
holman
316
150k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
121
130k
What the history of the web can teach us about the future of AI
inesmontani
PRO
3
820
Documentation Writing (for coders)
carmenintech
77
5.6k
Making Projects Easy
brettharned
120
6.9k
The Cost Of JavaScript in 2023
addyosmani
56
10k
Darren the Foodie - Storyboard
khoart
PRO
5
4.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Optimizing for Happiness
mojombo
378
72k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
490
30 Presentation Tips
portentint
PRO
1
470