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
面向对象设计1.pdf
Search
Yijie
December 03, 2020
Technology
0
25
面向对象设计1.pdf
Yijie
December 03, 2020
Tweet
Share
More Decks by Yijie
See All by Yijie
nothing_is_something.pdf
blowdy
0
14
Other Decks in Technology
See All in Technology
Red Hat OpenStack Services on OpenShift
tamemiya
0
130
SREじゃなかった僕らがenablingを通じて「SRE実践者」になるまでのリアル / SRE Kaigi 2026
aeonpeople
6
2.6k
Agile Leadership Summit Keynote 2026
m_seki
1
670
OpenShiftでllm-dを動かそう!
jpishikawa
0
140
Bedrock PolicyでAmazon Bedrock Guardrails利用を強制してみた
yuu551
0
260
生成AIと余白 〜開発スピードが向上した今、何に向き合う?〜
kakehashi
PRO
0
160
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
150
OCI Database Management サービス詳細
oracle4engineer
PRO
1
7.4k
プロポーザルに込める段取り八分
shoheimitani
1
650
コンテナセキュリティの最新事情 ~ 2026年版 ~
kyohmizu
6
2k
【Oracle Cloud ウェビナー】[Oracle AI Database + AWS] Oracle Database@AWSで広がるクラウドの新たな選択肢とAI時代のデータ戦略
oracle4engineer
PRO
2
190
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
5
1.6k
Featured
See All Featured
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
140
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
140
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
190
The Invisible Side of Design
smashingmag
302
51k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
230
Build your cross-platform service in a week with App Engine
jlugia
234
18k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
300
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
920
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
170
Transcript
面向对象设计 设计具有单一职责的类
面向对象系统 • 基础:消息 • 组织结构:类 • 设计的核心:消息 • 标准:编写既定范围的一个实现方式;易于更改的应用程序(知 识、技能、创造力)。
决定类的内容 • 应用程序(组织代码,编写代码) • 将方法分组成类 • 组织代码以便于更改
组织易于更改的代码 • 没有意想不到的副作用 • 轻微的需求变动对代码更改也较小 • 易于重用
创建具有单一职责的类 • 示例:自行车和齿轮 • 齿比(比较不同的齿轮)
• 一个计算齿轮比率的 程序 添加需求:不一样的车轮
添加需求(不一样的车轮)
这个代码组织方式是最好的吗? • 视情况而定 • 固定程序 • 需要易于更改适应未来需求
单一职责的重要性 • 单一职责、积木模式 • 多职责,难以重用,职责纠缠不清,迷惑
一个类的单一职责 • 提问 • Hey,齿轮,你的比率是多少 • Hey,齿轮,你的轮胎是多少 • 一句话描述 •
和、或 • 设计决策
拥抱变化 • 依赖行为,不依赖数据 • DRY(每一个细小的行为都只存在于一个地方)
隐藏实例变量 • 公有 • 私有 • 保护代码,避免受到意想不到的变化影响。 • 数据的行为不确定性
隐藏数据结构 • 1.调用依赖hash结构 • 2. 不受外部数据结构影响,可读性,拥抱变化
全面推行单一职责 • 将额外的责任从方法提取出来 • 方法也应该是单一职责的 • 将类里的额外职责隔离起来 • Gear •
Wheel
condition averse Nil MIssingAnimal Null Object Pattern