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
面向对象设计1.pdf
Search
Yijie
December 03, 2020
Technology
29
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
面向对象设计1.pdf
Yijie
December 03, 2020
More Decks by Yijie
See All by Yijie
nothing_is_something.pdf
blowdy
0
17
Other Decks in Technology
See All in Technology
増え続けるプロダクトの品質をどう担保するか。ProductSpecとTypeScriptによる取り組み
joere
3
420
続・ソフトウェアアーキテクトのための意思決定術: Decision Readiness, Revisited — When AI Changes the Economics of Software Architecture
snoozer05
PRO
9
2.5k
AI Agent 時代のデータ基盤: ClickHouse で実現する 超高速分析とコスト削減の両立
jozono
0
200
お客様の「やりたい」の先を見通す合意形成プロセス ~裏にある課題と不安を解きほぐすコツ~
yukakoseki
0
110
AIに任せられるFlutterコードベースを作る 〜仕様をコードで表し、ハーネスで守る〜
myohei
1
640
`go get`したらELFが降ってきた件
taiyow
0
180
AIがGISを代替する日:〜すべてをAIが創る時代に、私たちがFOSS4Gに関わる意味〜
lehupa
1
210
公共システムAdventCalendar2026
toru_kubota
0
260
Deep Data Security 機能解説
oracle4engineer
PRO
3
1k
Sinatra on PicoRuby ローカルでセルフホスト
bash0c7
0
100
Kiro Crew 入門 (手を離しても進む仕事) | 目指せ Kiro マスター 11
inariku
PRO
3
420
視野はAIに、視座は人に / ai-for-breadth-humans-for-perspective
nkzn
6
3.1k
Featured
See All Featured
Accessibility Awareness
sabderemane
1
290
Into the Great Unknown - MozCon
thekraken
41
2.8k
The Curse of the Amulet
leimatthew05
3
17k
Rails Girls Zürich Keynote
gr2m
96
14k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
The Curious Case for Waylosing
cassininazir
1
610
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
970
Designing Experiences People Love
moore
143
24k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
570
Mind Mapping
helmedeiros
1
430
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Transcript
面向对象设计 设计具有单一职责的类
面向对象系统 • 基础:消息 • 组织结构:类 • 设计的核心:消息 • 标准:编写既定范围的一个实现方式;易于更改的应用程序(知 识、技能、创造力)。
决定类的内容 • 应用程序(组织代码,编写代码) • 将方法分组成类 • 组织代码以便于更改
组织易于更改的代码 • 没有意想不到的副作用 • 轻微的需求变动对代码更改也较小 • 易于重用
创建具有单一职责的类 • 示例:自行车和齿轮 • 齿比(比较不同的齿轮)
• 一个计算齿轮比率的 程序 添加需求:不一样的车轮
添加需求(不一样的车轮)
这个代码组织方式是最好的吗? • 视情况而定 • 固定程序 • 需要易于更改适应未来需求
单一职责的重要性 • 单一职责、积木模式 • 多职责,难以重用,职责纠缠不清,迷惑
一个类的单一职责 • 提问 • Hey,齿轮,你的比率是多少 • Hey,齿轮,你的轮胎是多少 • 一句话描述 •
和、或 • 设计决策
拥抱变化 • 依赖行为,不依赖数据 • DRY(每一个细小的行为都只存在于一个地方)
隐藏实例变量 • 公有 • 私有 • 保护代码,避免受到意想不到的变化影响。 • 数据的行为不确定性
隐藏数据结构 • 1.调用依赖hash结构 • 2. 不受外部数据结构影响,可读性,拥抱变化
全面推行单一职责 • 将额外的责任从方法提取出来 • 方法也应该是单一职责的 • 将类里的额外职责隔离起来 • Gear •
Wheel
condition averse Nil MIssingAnimal Null Object Pattern