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
Object Oriented Training - Session 4
Search
hatelove
July 09, 2012
Technology
5.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Object Oriented Training - Session 4
里氏替換原則、最小知識原則、介面隔離原則、依賴反轉原則
hatelove
July 09, 2012
More Decks by hatelove
See All by hatelove
1. 在沙箱中開發
hatelove
12
3.1k
BDD in .NET - TDD 在實務上的最後一塊拼圖
hatelove
4
3k
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 3
hatelove
1
11k
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
え、こんなに早く改修できるの?──新人エンジニアとスクラムマスターの2人が語る、AI×アジャイル開発の現場
ysasago
0
150
データ界隈LT祭 第1回LT登壇
taromatsui_cccmkhd
2
1.4k
積み重なった技術負債への挑戦 〜初手としての全社ゴト化〜
techtekt
PRO
0
1.3k
生成AIエージェントを用いた、 手動テスト手順書から自動テストへの 変換手法の検討
magicpod
0
160
映像変換サーバーなしで端末内でHLSを生成してライブ配信
hikarusato
0
120
「ピッケル本」日本語版は4.0(第6版)が出版されるべき / pickaxe4-nagoyark05
kakutani
1
170
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
5
1.8k
Claude Code本って、 読む必要あるの?
oikon48
2
470
TinyGo 開発サイクルを高速化する:Go で作るエミュレータ入門
zozotech
PRO
1
740
リアーキテクチャ後の障害ゼロを目指したShadow Testingの取り組み
nihonbuson
PRO
1
110
安心して変更できるWebフロントエンドの作り方
pirosikick
5
2.7k
新機種発売前に見直そう!端末移行で再ログインが要るアプリ・要らないアプリは何が違うのか 〜シームレスに再開できる設計と実装〜
zozotech
PRO
0
200
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Tell your own story through comics
letsgokoyo
1
1.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
420
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
520
It's Worth the Effort
3n
188
29k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Paper Plane
katiecoart
PRO
4
53k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
410
Docker and Python
trallard
47
4.2k
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