- 浏览: 746424 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (419)
- 杂软粉墨 (2)
- 创意灵感 (3)
- 经验记录 (137)
- 开源轨迹 (2)
- sip-communicator (2)
- 闲侃杂谈 (8)
- 问题交流 (24)
- 概念模式 (32)
- 难点备案 (5)
- JwChat (1)
- 中国象棋 (1)
- 教育探索 (6)
- 英语研究 (58)
- 星际争霸 (1)
- 电信知识 (1)
- 软件架构 (3)
- 哲学探索 (26)
- 算法灵魂 (8)
- 近视探索 (6)
- 数学数学 (3)
- 牛角钻尖 (23)
- 至强文言 (3)
- 数据结构 (1)
- 宇宙物理 (2)
- 网络架构 (3)
- 游戏领域 (4)
- 图形处理 (2)
- 修炼之路 (8)
- 读书天地 (20)
- 编解乱码 (2)
- 概念探索 (8)
- 格物致知 (1)
- 其它语言 (1)
- 测试领域 (3)
- 文化风流 (1)
- JQuery (1)
- 網頁領域 (1)
- Unix/Linux (1)
- Inside JVM (1)
- 异常分析 (1)
最新评论
-
suyujie:
引用
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
iamzhoug37:
您能说一下"局部变量不受文本顺序限制" 是 ...
声明前为什么能赋值却不能输出,都是使用
Prefer interfaces to abstract classes
其中一段:
Interfaces allow the construction of nonhierarchical type frameworks.
Type hierarchies are great for organizing some things, but other things don’t fall
neatly into a rigid hierarchy. For example, suppose we have an interface representing
a singer and another representing a songwriter:
public interface Singer {
AudioClip sing(Song s);
}
public interface Songwriter {
Song compose(boolean hit);
}
In real life, some singers are also songwriters. Because we used interfaces
rather than abstract classes to define these types, it is perfectly permissible for a
single class to implement both Singer and Songwriter. In fact, we can define a
third interface that extends both Singer and Songwriter and adds new methods
that are appropriate to the combination:
public interface SingerSongwriter extends Singer, Songwriter {
AudioClip strum();
void actSensitive();
}
You don’t always need this level of flexibility, but when you do, interfaces are
a lifesaver. The alternative is a bloated class hierarchy containing a separate class
for every supported combination of attributes. If there are n attributes in the type
system, there are 2^n possible combinations that you might have to support.
This is
what’s known as a combinatorial explosion. Bloated class hierarchies can lead to
bloated classes containing many methods that differ only in the type of their arguments,
as there are no types in the class hierarchy to capture common behaviors
.
问题:
1. 这里提到的在type system中的attributes是指什么,因为对示例接口而言,没有域,难不成是指方法?
2. 为什么会有2^n种可能组合?假如有abc三个属性,那是(),(a),(b),(c),(a,b),(a,c)(b,c),(a,b,c)=2^3
如果是这个意思,它又要如何support?
3.
Bloated class hierarchies can lead to bloated classes containing many
methods that differ only in the type of their arguments, why?
为什么只能在参数类型上有区别?
4. there are no types in the class hierarchy to capture common behaviors?
这句话如何解释?
thanks in advance!
my answer:
因为是替代方案,所以试着对比着来看
interface:
public interface SingerSongwriter extends Singer, Songwriter {
AudioClip strum();
void actSensitive();
}
实际上它有4个方法
bloated class hierarchy:
就可能有
class SingerSongwriter extends Singer{
AudioClip sing(Song s);
Song compose(boolean hit);
AudioClip strum();
void actSensitive();
}
or
class SingerSongwriter extends Songwriter {
AudioClip sing(Song s);
Song compose(boolean hit);
AudioClip strum();
void actSensitive();
}
但
无论哪一种,都会缺失一种类型(there are no types in the class hierarchy to capture
common behaviors),以及可能连带缺失的类型,比如Song等,这样可能就会导致Bloated class hierarchies
can lead to bloated classes containing many methods that differ only in
the type of their arguments。
同时也满足了一个类包含所有可能属性组合(The alternative is a
bloated class hierarchy containing a separate class for every supported
combination of
attributes.),我觉得这里可以把attributes理解为方法之类的,方法也属于对象属性之一。这里恰好是2^2=4,有点全组合的味道,
但是不知道strum()和actSensitive怎么来的,权且把strum看成是sing和compose组合的产物,actSensitive代
表全组合中的空,这样就能解释2^n,总的来说还有些牵强的地方,但不知道他说的是否100%精准。
发表评论
-
Head First HTML with CSS and XHTML
2012-03-27 14:50 974i finished it by fast reading a ... -
head first jquery
2012-03-22 10:21 1134Thursday, March 22, 2012 fi ... -
Software Architecture Design Patterns in Java
2011-05-13 22:53 813to be continued... -
Effective Java 2nd edition
2011-04-25 16:19 1015Item 3: Enforce the singleton p ... -
Clean Code: chapter 13~15
2011-04-20 17:20 1023What follows is a series of p ... -
Clean Code: chapter 11~12
2011-04-15 09:35 1053The startup process is a concer ... -
Clean Code: chapter 9~10
2011-04-12 11:49 997Yes, we’ve come a long way; but ... -
Clean Code: chapter 6~8
2011-04-06 17:05 8542011.04.07 Objects and D ... -
Open Stanford Course: programming methodology 04
2011-04-05 11:52 921because this is sort of pre thi ... -
Open Stanford Course: programming methodology 03
2011-04-04 13:01 951any questions to start off with ... -
Clean Code: chapter 1~5
2011-04-02 11:26 928you should try several diffe ... -
Open Stanford Course: programming methodology 02
2011-03-31 00:30 974If you are stuck in the back, j ... -
Open Yale Course: Frontiers of Biomedical Engineering 01
2011-03-30 11:21 905http://www.verycd.com/topics/28 ... -
Open Stanford Course: programming methodology 01
2011-03-25 11:00 925you can pick them up on the ... -
Java Puzzler
2011-03-24 23:58 10602011.03.24 now i've been thr ... -
How Computers Work
2011-03-04 09:58 1016Yes, im at last reading this fa ... -
The Java Language Specification Third Edition
2011-01-25 10:36 845starting day: 2011.01.25 -
Tricks of the Java Programming Gurus
2011-01-24 11:22 921In the world of programming, t ... -
Thinking in Java Fourth Edition
2011-01-17 15:59 987以前这些经典书籍都零零散散地阅览过,现在准备重新精读一遍,随时 ...
相关推荐
"Effective Java读书笔记" Effective Java是一本关于Java编程语言的经典书籍,本笔记主要总结了Java语言的发展历程、静态工厂方法的应用、构造器模式的使用等重要知识点。 一、Java语言的发展历程 Java语言的发展...
《Effective Java》是Java编程领域的一本经典著作,由Joshua Bloch撰写,该书的第三版继续提供了关于如何编写高效、优雅、可维护的Java代码的指导。以下是基于给出的目录和部分内容提取的一些关键知识点: ### 第一...
标题“effective-java.pdf”与描述“effective-java.pdf”表明本文档是关于Java编程实践的指南,且内容可能来自于一本名为《Effective Java》的书籍,该书是由Joshua Bloch编写,被广泛认为是Java编程的权威指南。...
《Effective Java》是Java开发领域的经典著作,作者Joshua Bloch深入浅出地阐述了编写高效、健壮的Java代码的技巧和最佳实践。以下是对该书部分内容的详细解释: 1. **产生和销毁对象** - Item1:静态工厂方法相比...
在编程领域,特别是Java开发中,"Effective Java"是一本非常经典的书籍,由Joshua Bloch撰写,书中提出了一系列最佳实践和设计原则,以帮助开发者编写出更高效、更安全的代码。根据提供的标题和描述,我们将探讨三个...
"Effective Java 读书分享" 《Effective Java》读书分享.pptx 是一本 Java 编程语言指南,旨在帮助开发者编写高质量、可维护的 Java 代码。该书包含 90 个条目,每个条目讨论一条规则,涵盖了 Java 编程语言的...
《Effective Enterprise Java》是Java开发领域的一本经典著作,由著名技术专家Bill Venners编著,被广大Java开发者誉为“四大名著”之一。这本书深入探讨了在企业级Java开发中如何写出高效、可维护和易于理解的代码...
《Effective C++ 2nd Edition》是一本由Scott Meyers撰写的经典C++编程指南,中文版的出现使得更多的中国开发者能深入理解C++的精髓。这本书的核心目标是帮助程序员写出更高效、更易于理解和维护的C++代码。在描述中...
《Effective Java》是Java编程领域的一本经典著作,由Joshua Bloch撰写,第二版发布于2008年。这本书旨在提供实用的编程指导,帮助开发者写出更高效、更可维护的Java代码。以下是对书中核心知识点的详细解读: 1. *...
Effective Java 3 学习记录 本学习记录主要介绍了 Effective Java 3 中的静态工厂方法和 Builder 模式两部分内容。 一、静态工厂方法 静态工厂方法是指返回类实例的命名规则,例如:from、of、valueOf、instance ...
### Effective Java - 创建和销毁对象 #### 第一条:用静态工厂方法代替构造器 **优点:** 1. **命名清晰,易于使用:** 静态工厂方法通过明确的命名方式,使得用户更容易理解方法的功能及其预期结果。例如,`...
《Effective Java》是一本经典Java编程指南,作者是Joshua Bloch,这本书深入探讨了如何编写高质量、高效、可维护的Java代码。以下是对压缩包中各章节主要知识点的详细阐述: 1. **第2章 创建和销毁对象** - 单例...
《Effective Java》是Java开发领域的一本经典著作,由Joshua Bloch撰写,书中提出了一系列编程最佳实践和设计模式,帮助开发者写出更高效、更可靠、更易于维护的Java代码。配套代码`effective-java-examples-master`...
《Effective Java》是Java编程领域的一本经典著作,由知名程序员和计算机科学家Joshua Bloch撰写。这本书的第二版深入探讨了如何编写高效、可维护的Java代码,并提供了许多实用的编程指南和最佳实践。以下是根据标题...
Item 18: Favor composition over inheritance Item 19: Design and document for inheritance or else prohibit it Item 20: Prefer interfaces to abstract classes Item 21: Design interfaces for posterity ...