Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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.2k
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.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.8k
Object Oriented Training - Session 1
hatelove
1
8.3k
Other Decks in Technology
See All in Technology
MySQLとPostgreSQLのコレーション / Collation of MySQL and PostgreSQL
tmtms
1
1.1k
業務のトイルをバスターせよ 〜AI時代の生存戦略〜
staka121
PRO
2
240
シニアソフトウェアエンジニアになるためには
kworkdev
PRO
3
210
20251219 OpenIDファウンデーション・ジャパン紹介 / OpenID Foundation Japan Intro
oidfj
0
350
IAMユーザーゼロの運用は果たして可能なのか
yama3133
2
510
通勤手当申請チェックエージェント開発のリアル
whisaiyo
3
310
アプリにAIを正しく組み込むための アーキテクチャ── 国産LLMの現実と実践
kohju
0
150
AgentCore BrowserとClaude Codeスキルを活用した 『初手AI』を実現する業務自動化AIエージェント基盤
ruzia
7
470
AWSに革命を起こすかもしれない新サービス・アップデートについてのお話
yama3133
0
430
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
9.8k
2025-12-18_AI駆動開発推進プロジェクト運営について / AIDD-Promotion project management
yayoi_dd
0
140
Amazon Bedrock Knowledge Bases × メタデータ活用で実現する検証可能な RAG 設計
tomoaki25
6
1.7k
Featured
See All Featured
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
260
Being A Developer After 40
akosma
91
590k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.8k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
60
37k
Making Projects Easy
brettharned
120
6.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
KATA
mclloyd
PRO
33
15k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
680
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
HDC tutorial
michielstock
0
260
Measuring & Analyzing Core Web Vitals
bluesmoon
9
710
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
47
33k
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