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
FizzBuzzで学ぶOCP
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Nokogiri
December 24, 2023
Technology
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
FizzBuzzで学ぶOCP
Nokogiri
December 24, 2023
More Decks by Nokogiri
See All by Nokogiri
Zustandを用いた実践的状態管理
undefined_name
3
940
React Testing Libraryでの WAI-ARIAロールの活用事例
undefined_name
1
220
自動テストは何の役に立つのか そして役に立たないのか
undefined_name
5
1.9k
Pipe Operator (|>) の紹介
undefined_name
2
410
エンジニアとQAでコラボするフロントエンドリアーキテクチャ開発の事例
undefined_name
4
3.3k
オブジェクト指向のプラクティスをフロントエンドで活用する
undefined_name
7
1.8k
モププロ@kintone開発チーム
undefined_name
1
680
勉強会で登壇者に 質問しづらい課題を解決する サービスをリリースしました🎉
undefined_name
2
1.4k
Usefull GitLens
undefined_name
3
930
Other Decks in Technology
See All in Technology
AI × アーキテクト 第1・2章|生成AIの課題とアーキテクトの素養
daidaidai
0
130
実践!Cloud Run ハンズオン!! / Cloud Run handson
y0hgi
2
270
【Data Engineering Summit2026_登壇資料】医療ビッグデータ×AIエージェントを支えるデータ基盤とハーネスエンジニアリング
jmdc_presentation
0
160
hackers_champloo_2026_tidb
makocchi
0
150
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
140
Getting Started with Google Antigravity
glaforge
0
280
AIがコードを書く時代に、エンジニアは何で自分の価値を証明するのか / In an era where AI writes code how do engineers prove their value
carta_engineering
3
1k
日本語に強いオープンな大規模言語モデル「LLM-jp」
odashi
4
1.1k
分析の民主化を支えるメタデータ整備の実践
kakehashi
PRO
4
1.4k
Local CI × GitHub Actions
gogutan
2
140
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
220
パッチ更新でterraform initが落ちた日
grimoh
1
140
Featured
See All Featured
Marketing to machines
jonoalderson
1
5.9k
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
630
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Making the Leap to Tech Lead
cromwellryan
135
10k
Agile that works and the tools we love
rasmusluckow
331
22k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Side Projects
sachag
456
43k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Transcript
FizzBuzzͰֶͿOCP Reboot kansai.ts #4 2023/11/22 Nokogiri
Nokogiri(@nkgrnkgr) αΠϘζגࣜձࣾ | ϑϩϯτΤϯυΤϯδχΞ KintoneͷϑϩϯτΤϯυͷج൫৽ϓϩδΣΫτͰ ϑϩϯτΤϯυΤϯδχΞΛ͍ͯ͠·͢ɻ ϙέϞϯରઓΨνʢϙέιϧͷμϝܭࢉπʔϧͷ։ ൃʣɺೋࣇͷ
FizzBuzzͱʁ • ϓϩάϥϛϯάͨ͜͠ͱ͕͋ΔਓͳΒҰฉ͍ͨ͜ͱ͕͋Δݴ༿༡ ͼͰ͢ɻ • ྫʣ̏ͷഒͰ Fizzɺ̑ͷഒͰBuzzɺ̏ͱ̑ͷഒͷͱ͖ʹ FizzBuzzͱ͍͏ • ϓϩάϥϛϯάͷ࿅शͱͯ͠Α͘ΘΕ·͢ɻ
• ࠓ͜ͷFizzBuzzΛͬͯOCPʹ͍ͭͯઆ໌͠·͢ɻ
OCPͬͯͳʹʁ • ΦϒδΣΫτࢦͷݪଇ SOLIDͷҰ෦ • ։์ดݪଇOpen Closed PrincipleʢOCPʣͷུ • ֦ுʹରͯ͠Φʔϓϯ
• มߋʹରͯ͠Ϋϩʔζυ
γϯϓϧͳ FizzBuzz // 3ͷഒͷ߹Fizz // 5ͷഒͷ߹Buzz // 3ͱ5ͷഒͷ߹FizzBuzz // ͱදࣔ͢Δ
export const fizzBuzz = (num: number): string => { if (num % 3 === 0 && num % 5 === 0) { return "FizzBuzz"; } if (num % 3 === 0) { return "Fizz"; } if (num % 5 === 0) { return "Buzz"; } return ""; }; 3ͷഒͷ߹Fizz 5ͷഒͷ߹Buzz 3ͱ5ͷഒͷ߹FizzBuzz ͦΕҎ֎ͷ߹"" Λฦ͢
͜Ε༷ͬͯมߋʹڧ͍ʁ
͜Ε༷ͬͯมߋʹڧ͍ʁ • ഒ̏̑Ͱͳ͍͔͠Εͳ͍ʁ • ϧʔϧՃ͞ΕΔ͔͠Εͳ͍ʁ • ฦ͢จࣈྻʮFizzʯʮBuzzʯ ͔ΒʮΘΜʯʮʹΌΜʯʹมΘΔ͔ʁ → ͜ͷͨͼʹ
fi zzBuzzؔΛमਖ਼͢Δͷෆ۩ ߹ͷݪҼʹͳΔͷͰʁ
༷ͷຊ࣭ // 3ͷഒͷ߹Fizz // 5ͷഒͷ߹Buzz // 3ͱ5ͷഒͷ߹FizzBuzz // ͱදࣔ͢Δ export
const fizzBuzz = (num: number): string => { if (num % 3 === 0 && num % 5 === 0) { return "FizzBuzz"; } if (num % 3 === 0) { return "Fizz"; } if (num % 5 === 0) { return "Buzz"; } return ""; }; Λೖྗ͢ΔͱจࣈྻΛฦ ͢ ҙͷมϧʔϧΛෳఆٛͰ ͖Δ มϧʔϧԿΒ͔ͷఆ݅ Λຬͨͨ͠ͱ͖ʹదԠ͞ΕΔ
֦ுʹରͯ͠Φʔϓϯ มߋʹରͯ͠Ϋϩʔζυ ʹͯ͠ΈΔ
ίʔυҊ // 3ͷഒͷ߹Fizz // 5ͷഒͷ߹Buzz // 3ͱ5ͷഒͷ߹FizzBuzz // ͱදࣔ͢Δ export
const fizzBuzz = (num: number): string => { if (num % 3 === 0 && num % 5 === 0) { return "FizzBuzz"; } if (num % 3 === 0) { return "Fizz"; } if (num % 5 === 0) { return "Buzz"; } return ""; }; RuleΛ࡞Δ Matchɿೖྗʹ߹க͢Δ ݅Λදݱ͢Δ apply: ݅ʹ߹கͨ͠߹ ͷॲཧΛදݱ͢Δ RULE_SETS: దԠ͞ΕΔ ϧʔϧͱॱ൪Λදݱ͢Δ
ίʔυҊ // 3ͷഒͷ߹Fizz // 5ͷഒͷ߹Buzz // 3ͱ5ͷഒͷ߹FizzBuzz // ͱදࣔ͢Δ export
const fizzBuzz = (num: number): string => { if (num % 3 === 0 && num % 5 === 0) { return "FizzBuzz"; } if (num % 3 === 0) { return "Fizz"; } if (num % 5 === 0) { return "Buzz"; } return ""; }; ֦ுʹΦʔϓϯɿϧʔϧΛ Ճ͢Δ߹৽͘͠ϧʔϧΛ ఆٛͯ͠RULE_STESʹՃ ͢Δ͚ͩ มߋʹΫϩʔζυɿϝΠϯͷ ॲཧͰ͋Δ fi zzBuzzʹӨڹ Λ༩͑ͳ͍ɻมߋରͷϧʔ ϧͷΈमਖ਼Ͱ͖Δ
·ͱΊ • ίʔυͷຊ࣭తͳ༷ʹணͯ͠Ͳ͕֦͜ுɾมߋ͞Ε͍͢ͷ͔ߟ ͑Δ • FizzBuzzαϯϓϧͰ͍ΖΜͳॲཧʹԠ༻Մೳ • ྫʣೖྗͷHTML/JSON/Text ʹ߹ΘͤͯύʔαʔͷॲཧΛΓସ͑ Δ
• ༷ͷՃɾมߋ͕ϝΠϯͷॲཧʹӨڹΛ༩͑ͳ͍Α͏ʹ͢Δͷ͕େ ࣄ
αΠϘζͰΤϯδχΞΛืू͍ͯ͠·͢ʂ
͝ࢼௌ͋Γ͕ͱ͏͍͟͝·ͨ͠😊