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 4
Search
hatelove
July 09, 2012
Technology
1
5.1k
Object Oriented Training - Session 4
里氏替換原則、最小知識原則、介面隔離原則、依賴反轉原則
hatelove
July 09, 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 3
hatelove
1
11k
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
DMARCは導入したんだけど・・・現場のつぶやき 〜 BIMI?何それ美味しいの?
hirachan
1
160
初海外がre:Inventだった人間の感じたこと
tommy0124
1
200
最近読んで良かった本 / Yokohama North Meetup #10
mktakuya
0
1k
MCP サーバーの基礎から実践レベルの知識まで
azukiazusa1
24
11k
kotlin-lsp の開発開始に触発されて、Emacs で Kotlin 開発に挑戦した記録 / kotlin‑lsp as a Catalyst: My Journey to Kotlin Development in Emacs
nabeo
2
360
OPENLOGI Company Profile for engineer
hr01
1
46k
Pythonで構築する全国市町村ナレッジグラフ: GraphRAGを用いた意味的地域検索への応用
negi111111
5
1.4k
文字列操作の達人になる ~ Kotlinの文字列の便利な世界 ~ - Kotlin fest 2025
tomorrowkey
2
520
Playwrightで始めるUI自動テスト入門
devops_vtj
0
190
AIエージェントを導入する [ 社内ナレッジ活用編 ] / Implement AI agents
glidenote
1
230
激動の2025年、Modern Data Stackの最新技術動向
sagara
0
960
ソフトウェアテストのAI活用_ver1.50
fumisuke
0
160
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
331
21k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Facilitating Awesome Meetings
lara
57
6.6k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.2k
Navigating Team Friction
lara
190
15k
The World Runs on Bad Software
bkeepers
PRO
72
11k
Done Done
chrislema
186
16k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.2k
Thoughts on Productivity
jonyablonski
72
4.9k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
Transcript
Trainer: Joey Chen Date: 2012/07/02 Object Oriented Training – Session
4
- 2 - 回顧 – OO三特性 封裝 繼承 多型
- 3 - 回顧 – 抽象 interface abstract
- 4 - 回顧 – SOLID S • 單一職責原則 O
• 開放封閉原則 L I D
SOLID
Liskov Substitution Principle 里氏替換原則
- 7 -
- 8 - Liskov Substitution Principle • 情況 – 當父類行為不符合子類需求,且子類無法
override 時 – 當子類繼承父類,卻無法正常替代父類運作時 • 規範繼承關係 – 確保多型可正常運作
SOLID
Least Knowledge Principle ( Law of Demeter ) 最少知識原則 (
狄米特法則 )
- 11 -
- 12 - Least Knowledge Principle • 規範封裝範圍 • 任何物件對外只開放
– 最少且缺一不可的資訊
SOLID
Interface Segregation Principle 介面隔離原則
- 15 - 哪一個方便使用
- 16 - Interface Segregation Principle • 介面的單一職責 – 介面也應該內聚,避免出現「胖」介面
• 規範依賴程度 – 一個物件對另一個物件的依賴,應建立在最小的介面上 – 不要強迫依賴了沒使用的方法,這是種介面污染 胖
SOLID
Dependency Inversion Principle 依賴反轉原則
- 19 - Dependency Inversion Principle • 依賴於抽象 • 高層模組不依賴於底層模組
– 都依賴於抽象
- 20 - 依賴於介面
- 21 - 結論 S O L L I D
- 22 - 回顧
- 23 - 作業 – 幫DAO穿衣服 • 原本需求 – Product資料異動時,需記錄log,查詢不用
– 對Product進行CRUD時,需檢查權限 • 重構需求 – 將權限驗證與log相關職責,從ProductDao獨立出來 – 讓ProductDao只處理CRUD的需求 • 需求異動 – 在測試環境時,不檢查權限與不記錄log – 檢查測試環境條件,請使用Context.IsTestEnvironment
- 24 - 原始程式 class diagram
- 25 - 重構的 class diagram
Thanks for your listening Q & A