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
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
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.6k
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
FinOps × AIエージェントで実現する コストインシデントの自動調査
oasis1994liveforever
0
120
小さく始める AI 活用推進 ― 日経電子版 Web チームの事例/nikkei-tech-talk47
nikkei_engineer_recruiting
0
220
ポケモンの型をTypeScriptの型システムで表現してみた
subroh0508
0
370
[モダンアプリ勉強会]今更聞けないGit/GitHub入門
tsukuboshi
0
370
EventBridge Connection
_kensh
5
690
AAIFに入ってみた ~内から見えるコミュニティ動向~
sato4
0
160
Snowflakeと仲良くなる第一歩
coco_se
4
420
ルールやカスタム機能、どう活かす?ハンズオンで体感するIBM Bobの出力コントロール
muehara
1
130
あなたの AI ワークスペースに、 専門コーダーを連れてくる - Amazon Quick Desktop 最新情報
kawaji_scratch
1
130
ACE-Step-1.5で見る 音楽生成AIのしくみと“破綻だけ直す”Retake機能の開発【zennfes spring 2026 登壇資料】
personabb
1
130
MIERUNE JCT 発表資料「宇宙から伊能忠敬ごっこ」
syuchimu
0
210
Bucharest Tech Week 2026 - Reinventing testing practices in the AI era
edeandrea
PRO
1
140
Featured
See All Featured
New Earth Scene 8
popppiees
3
2.3k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
160
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
Mind Mapping
helmedeiros
PRO
1
240
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
250
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
580
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
180
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
250
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