惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
Apple Machine Learning Research
Apple Machine Learning Research
O
OpenAI News
酷 壳 – CoolShell
酷 壳 – CoolShell
The GitHub Blog
The GitHub Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
Engineering at Meta
Engineering at Meta
W
WeLiveSecurity
Hacker News: Ask HN
Hacker News: Ask HN
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
D
Docker
F
Full Disclosure
AI
AI
罗磊的独立博客
博客园 - 【当耐特】
U
Unit 42
S
SegmentFault 最新的问题
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Palo Alto Networks Blog
博客园_首页
H
Help Net Security
量子位
月光博客
月光博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 司徒正美
F
Fortinet All Blogs
D
DataBreaches.Net
B
Blog RSS Feed
Webroot Blog
Webroot Blog
TaoSecurity Blog
TaoSecurity Blog
S
Secure Thoughts
爱范儿
爱范儿
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Attack and Defense Labs
Attack and Defense Labs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
CERT Recently Published Vulnerability Notes
Martin Fowler
Martin Fowler
Blog — PlanetScale
Blog — PlanetScale
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Securelist

博客园 - KiddLee

数据库存储图像及使用Image控件显示 三层体系结构总结(六) Spring.Core IoC(一) Spring.Net 模块组成 Generating user instances in Sql Server is disabled. Use sp_configure 'user instances enabled' to generate user instances 面向对象分析设计学习与探索(六):好的设计=软件的灵活程度(good design=flexible software)继续 面向对象分析设计学习与探索(六):好的设计=软件的灵活程度(good design=flexible software) 面向对象分析设计学习与探索(五):分析(Analysis) 面向对象分析设计学习与探索(四):需求变化(Requirements Change) 面向对象分析设计学习与探索(三):收集需求(Gathering Requirement) 面向对象分析设计学习与探索(二):好的应用程序设计(Well-designed apps rock) 面向对象分析设计学习与探索(一):开篇 类型构造器 装箱拆箱续 Session Cookie and Persistent Cookie 第一次执行方法 我犯错了 装箱拆箱 接口函数还可以声明为private
面向对象分析设计学习与探索(六):面向对象的灾难(OO Catastrophe)
KiddLee · 2007-10-30 · via 博客园 - KiddLee

什么是接口?

这些代码结构有两种角色:一是,定义一些行为提供给更多类型;二是:把焦点集中在要使用这些类型的类上。(This code construct has two dual role of defining behavior that applies to multiple types, and also being the preferred focus of classes that use those types)

使用接口比实现让你的软件更容易扩展(Coding to an interface, rather than to an implementation, make your software easier to extend)

使用接口,你的代码可以使用此接口下的任何一个继承类型,并且在实现他们之前(By coding to an interface, your code will work with all of the interface’s subclasses-even ones that haven’t been created yet.)

看看这个例子:

OOAD5-2-1

这是一个运动员的例子:有一个运动员的接口,这个接口下面实现了一些实际的类型,如:足球运动员、棒球运动员、篮球运动员….在你编写代码时会有两种选择,你可以使用继承类型实现,比如说足球运动员,也可以使用接口Athlete,当你有这样的选择时,你会更喜欢使用接口而不是实现类型。因为实际类型局限性比较大。

OOAD5-2-2

这一点很重要,因为他能够加强程序的灵活性,

什么是封装?

比起其他的面向对象原则,它更能防止保持问题,使对象行为的变化要求局部化。(It’s been responsible for preventing more maintenance problems than any other OO principle in history, by localizing the changes required for the behavior of an object to vary.)

封装可以避免大量的代码拷贝粘贴,并且避免类型做不必要的改变。任何时候你觉得程序中的一个行为可能会改变,你想将这个行为从变化不太频繁的程序中远离。换句话说:封装变化

看看这个例子:

OOAD5-2-3

Painter类型有两个相对稳定的方法,但是paint ()在这个实现中会经常变化。所以让我们来封装变化,把paint()方法从Painter类型中移走。

OOAD5-2-4

什么是变化?

每一个类型尽可能只有一个变化点(Every class should attempt to make sure that it has only one reason to this, the death of many badly designed piece of software.)

在软件中永恒不变的就是变化,不好的设计会让软件在变化中崩溃,但是好的软件可以很轻松的改变。

每一个类型仅有一个变化原因会使你的软件相对简单的应对变化。换句话说:减少类型中变化点以降低类型变化的可能。

下面看看这个例子:

OOAD5-2-5

在这个类型中可能发生的变化点很多,这样有可能造成这个类型被不停的修改。但是如果改成下面的结构,那么每次的变化只是某一种类型的变化。

OOAD5-2-6

运用这些方法可以开始解决查询工具中那些代码的问题,我们来总结一下学习到的面向对象原则:

1、 封装变化(Encapsulate what varies)

2、 代码尽量依赖接口而不是实现(Code to an interface rather than to an implementation)

3、 程序中的每一个类型尽量只有一个变化点(Each class in your application should have only one reason to change)

下面我们将回到查询工具的代码上(未完,待续...)

面向对象分析设计学习与探索(六):好的设计=软件的灵活程度(good design=flexible software)继续