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
11k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Object Oriented Training - Session 3
1. 高內聚、低耦合
2. 單一職責原則
3. 開放/封閉原則
hatelove
July 04, 2012
More Decks by hatelove
See All by hatelove
1. 在沙箱中開發
hatelove
12
3k
BDD in .NET - TDD 在實務上的最後一塊拼圖
hatelove
4
2.9k
OO training 基本原則整理
hatelove
2
5.3k
OO training homework 3 review and summary
hatelove
1
11k
OO training homework 2 review and summary
hatelove
1
4.7k
OO training homework 1 review and summary
hatelove
1
8.1k
Object Oriented Training - Session 4
hatelove
1
5.2k
Object Oriented Training - Session 2
hatelove
1
4.9k
Object Oriented Training - Session 1
hatelove
1
8.4k
Other Decks in Technology
See All in Technology
副作用のある Lambda でも Lambda Power Tuning は使えるのか / lambda-power-tuning-side-effects
koukihosaka
1
130
[Droidcon Orlando '26] The Android Lens: Applying Mobile Forensics to AI Performance
amanda_hinchman
1
100
AIと1000本ノックしてたどり着いた、最速のプロダクト開発 ~toC向けAIエージェントUXを、動く選択肢とAIキャパシティで設計する~
lycorptech_jp
PRO
1
110
GoでCコンパイラを作った話
repunit
0
150
JAWS_ICEBERG_BASECAMP
iqbocchi
2
110
文字起こし基盤の信頼性
abnoumaru
0
110
AIが当たり前の組織で エンジニアはどう育つか
nishihira
1
920
AI時代の開発生産性は、個人技からチーム設計へ
moongift
PRO
4
2.5k
ダッシュボード"開発"について 〜使われるダッシュボードのつくりかた〜
kimichan
0
180
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.5k
AI時代のYAGNI:「爆速で無駄になった機能」からの学び / 20260720 Naoki Takahashi
shift_evolve
PRO
3
510
AI Coding Agent時代のcdk-nagガードレール 〜組織ルールを強制CIで守り抜く設計の挑戦〜
mhrtech
3
490
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
46
8.2k
The Curious Case for Waylosing
cassininazir
1
440
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
620
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
190
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
エンジニアに許された特別な時間の終わり
watany
108
250k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
220
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
370
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.4k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
250
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