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
26
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
14
Other Decks in Technology
See All in Technology
Conditional PED-ANOVA: Hyperparameter Importance in Hierarchical & Dynamic Search Spaces
pfn
PRO
0
130
WasmをRustにする
sansantech
PRO
0
250
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
190
継続的なAIコスト最適化
bgpat
1
340
パッチ更新でterraform initが落ちた日
grimoh
1
140
Running Kotlin + Quarkus with Lambda
nealle
1
3.7k
Rustuna: Rustによる高速なOptuna実装
pfn
PRO
0
190
会社説明資料
persolserverworks
0
9.8k
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
0
290
二歩目のフロントエンド・ウェブアクセシビリティ
camiha
2
570
アウトプット初心者、半年間のふりかえり
4o1sobblue
0
430
AIがコードを書く時代に、エンジニアは何で自分の価値を証明するのか / In an era where AI writes code how do engineers prove their value
carta_engineering
3
1.1k
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
220
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
360
Building Adaptive Systems
keathley
44
3.2k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
940
Claude Code のすすめ
schroneko
67
230k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.4k
Mobile First: as difficult as doing things right
swwweet
225
10k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
The Limits of Empathy - UXLibs8
cassininazir
2
720
Transcript
面向对象设计 设计具有单一职责的类
面向对象系统 • 基础:消息 • 组织结构:类 • 设计的核心:消息 • 标准:编写既定范围的一个实现方式;易于更改的应用程序(知 识、技能、创造力)。
决定类的内容 • 应用程序(组织代码,编写代码) • 将方法分组成类 • 组织代码以便于更改
组织易于更改的代码 • 没有意想不到的副作用 • 轻微的需求变动对代码更改也较小 • 易于重用
创建具有单一职责的类 • 示例:自行车和齿轮 • 齿比(比较不同的齿轮)
• 一个计算齿轮比率的 程序 添加需求:不一样的车轮
添加需求(不一样的车轮)
这个代码组织方式是最好的吗? • 视情况而定 • 固定程序 • 需要易于更改适应未来需求
单一职责的重要性 • 单一职责、积木模式 • 多职责,难以重用,职责纠缠不清,迷惑
一个类的单一职责 • 提问 • Hey,齿轮,你的比率是多少 • Hey,齿轮,你的轮胎是多少 • 一句话描述 •
和、或 • 设计决策
拥抱变化 • 依赖行为,不依赖数据 • DRY(每一个细小的行为都只存在于一个地方)
隐藏实例变量 • 公有 • 私有 • 保护代码,避免受到意想不到的变化影响。 • 数据的行为不确定性
隐藏数据结构 • 1.调用依赖hash结构 • 2. 不受外部数据结构影响,可读性,拥抱变化
全面推行单一职责 • 将额外的责任从方法提取出来 • 方法也应该是单一职责的 • 将类里的额外职责隔离起来 • Gear •
Wheel
condition averse Nil MIssingAnimal Null Object Pattern