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
Object Oriented Training - Session 3
Search
hatelove
July 04, 2012
Technology
1
11k
Object Oriented Training - Session 3
1. 高內聚、低耦合
2. 單一職責原則
3. 開放/封閉原則
hatelove
July 04, 2012
Tweet
Share
More Decks by hatelove
See All by hatelove
1. 在沙箱中開發
hatelove
12
3k
BDD in .NET - TDD 在實務上的最後一塊拼圖
hatelove
4
2.8k
OO training 基本原則整理
hatelove
2
5.2k
OO training homework 3 review and summary
hatelove
1
11k
OO training homework 2 review and summary
hatelove
1
4.6k
OO training homework 1 review and summary
hatelove
1
8k
Object Oriented Training - Session 4
hatelove
1
5.1k
Object Oriented Training - Session 2
hatelove
1
4.8k
Object Oriented Training - Session 1
hatelove
1
8.3k
Other Decks in Technology
See All in Technology
2025-07-31: GitHub Copilot Agent mode at Vibe Coding Cafe (15min)
chomado
2
310
Perlアプリケーションで トレースを実装するまでの 工夫と苦労話
masayoshi
1
350
AI エンジニアの立場からみた、AI コーディング時代の開発の品質向上の取り組みと妄想
soh9834
8
630
【CEDEC2025】大規模言語モデルを活用したゲーム内会話パートのスクリプト作成支援への取り組み
cygames
PRO
2
640
モバイルゲームの開発を支える基盤の歩み ~再現性のある開発ラインを量産する秘訣~
qualiarts
0
1k
Kiroから考える AIコーディングツールの潮流
s4yuba
3
590
Google Cloud で学ぶデータエンジニアリング入門 2025年版 #GoogleCloudNext / 20250805
kazaneya
PRO
7
1.5k
AIに全任せしないコーディングとマネジメント思考
kikuchikakeru
0
380
【CEDEC2025】現場を理解して実現!ゲーム開発を効率化するWebサービスの開発と、利用促進のための継続的な改善
cygames
PRO
0
650
LLMでAI-OCR、実際どうなの? / llm_ai_ocr_layerx_bet_ai_day_lt
sbrf248
0
410
猫でもわかるQ_CLI(CDK開発編)+ちょっとだけKiro
kentapapa
0
190
Vision Language Modelと自動運転AIの最前線_20250730
yuyamaguchi
3
1k
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
110
19k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
770
Agile that works and the tools we love
rasmusluckow
329
21k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Building an army of robots
kneath
306
45k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.4k
BBQ
matthewcrist
89
9.8k
Speed Design
sergeychernyshev
32
1k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.4k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
182
54k
Transcript
Trainer: Joey Chen Date: 2012/06/18 Object Oriented Training – Session
3
- 2 - 高內聚、低耦合
- 3 - 內聚
- 4 - 耦合
- 5 - 高內聚、低耦合
- 6 - 高內聚、低耦合
SOLID
Single Responsibility Principle (SRP) 單一職責原則
- 9 - 多職責
- 10 - 單一職責 • 3 layer • MVC
- 11 - 單一職責 • 避免一個class擁有多個職責 • 避免一個職責散落在多個class中
SOLID
Open Closed Principle (OCP) 開放封閉原則
- 14 - 對擴充開放,對修改封閉
- 15 - 開放封閉原則 • 判斷方式 – 當新增或修改需求時,可以新增class,而使用場景不需改變程 式,即符合開放封閉原則 –
當多一種新的可能時,在同一個class中(非工廠類別),使用if else來修改舊有邏輯,即違反開放封閉原則
- 16 - 案例 – 高內聚、低耦合
- 17 - 回顧
- 18 - 結論 • 抽象思考,釐清職責 • 新增class進行抽換,而不是修改、擴充舊的class • 好的Class特色
– 乾淨、清楚、簡單 – 容易組合與抽換
- 19 - 結論 • 高內聚、低耦合為設計目的 • 原則為設計精神 – 符合原則即可達到目的
• Design patterns – 針對不同需求 – 滿足這些原則的best practice – 達到高內聚、低耦合的目的
- 20 - 作業 – 重構 • 說明 – 決定便利商店的種類,未來可能不是從config讀取
– 資料來源可能會改變 – 未來可能會新增其他便利商店種類 • 注意 – 請將每個Class的職責說明,記錄於Class的summary document 上 – 請將職責獨立的Class,放到Library中,除非該Class是專屬於網 站的職責 – 請參考Selenium的Test Cases
- 21 -
Thanks for your listening Q & A