Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
【JavaScript】Strategy Patternっぽいのをちょい使いしてif分を駆逐する
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
TomPenguin
October 26, 2022
Programming
220
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
360
【JavaScript】クロージャを理解して正しく使う
tompenguin
0
540
Git ゼンゼン ムズカシクナイ
tompenguin
0
560
あきらめる Atomic Design
tompenguin
5
760
Other Decks in Programming
See All in Programming
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.4k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
560
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
140
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
160
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
320
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
220
OpenSpecのproposalにbrainstormingを持たせてみた
tigertora7571
1
210
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
640
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.5k
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
250
Android CLI
fornewid
0
220
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
440
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
380
Large-scale JavaScript Application Architecture
addyosmani
515
110k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
The Invisible Side of Design
smashingmag
301
52k
RailsConf 2023
tenderlove
30
1.5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
630
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
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