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
More Decks by TomPenguin
See All by TomPenguin
Domain Modelを共有していい感じにプロダクトを作る
tompenguin
0
370
【JavaScript】クロージャを理解して正しく使う
tompenguin
0
550
Git ゼンゼン ムズカシクナイ
tompenguin
0
570
あきらめる Atomic Design
tompenguin
5
770
Other Decks in Programming
See All in Programming
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
470
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
260
Androidだけじゃない、DroidKaigiで広がった私の技術スタック
akkeylab
0
120
wkhtmltopdfの次どうするか問題2026
willnet
2
1.9k
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
7.5k
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
190
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
140
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
160
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
710
The Rails Doctrine Decade
koic
2
510
Java 27新機能 / Java 27 new features
kishida
2
200
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
390
Featured
See All Featured
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
370
What's in a price? How to price your products and services
michaelherold
247
13k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Exploring anti-patterns in Rails
aemeredith
4
520
Mind Mapping
helmedeiros
1
390
Transcript
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