汇总一些平时碰到的Java方面的疑问备忘。
Java中的静态内部类(static inner class)
在学习Thinking in Patterns with Java的Pattern refactoring中的//: refactor:trash:Trash.java的源代码时,发现静态内部类的使用,如下:
|
后面使用Messager类是这样的:
|
经过查阅资料,得出下面的理解:
1、为什么用内部类?
答:因为Messenger的作用仅是为产生Trash而使用来封装信息的辅助类,其它地方也用不着,所以放在Trash类的内部;
2、为什么用静态的内部类?
答:因为使用静态的内部类可以在其包含它的外部类没有生成实际对象时生成这个内部类,而在这里,在Messenger对象生成之前根本就不能生成它的外部类Trash的对象;就算是其它某种情况可以先生成外部类,如果没有先生成外部类的必要性,我认为,应该尽量使用静态内部类,因为,何必要生成一个没有用的多余的外部类对象呢?(这个观点没有深入的的学习和验证,也许不正确!)
参考资料:
1、Thinking in Java, 3rd ed. Revision 4.0 Nested classes
./aaa-TIJ3-distribution/html/TIJ310.htm#Heading7630
|
2、一篇完整叙述Java内部类的文章:
转:java内部类
你有两个选择(转自朋友的邮件)
转载者前言:
太多的时候,我们都不能改变客观环境,但我们可以自由的改变思考的角度和主观心情。我觉得,人生快乐与否很大程度上取决于自己是否会进行选择:您可以选择快乐,也可以选择痛苦。就这么简单。
转帖正文,后附朋友发送的ppt演示文档。在此感谢这位朋友发来这么好的东西。并与所有朋友分享。
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
Jerry是美国一家餐厅的经理,他总是心情非常好,
当别人问他最近过得如何时,
他总是有好消息同大家说。
他总是回答:
『我一直都很幸福!』
当他换工作的时候,
许多服务生都跟着他
从这家餐厅换到另一家。
为什么呢?
因为Jerry是个天生的激励者!
如果有某位员工今天运气不好,
Jerry总是适时地告诉那位员工
往好的方面想。
看到这样的情境,真的让我很好奇,所以有一天我到Jerry那儿问他:
我不懂,没有人能够老是那样地积极乐观,你是怎么办到的?
Jerry回答:
『每天早上,当我起来的时候我告诉自己:
我今天有两种选择 ,
我可以选择好心情,
或者我可以选择坏心情。
我总是选择好心情』
『即使有不好的事发生,
我可以选择做个受害者,
或是选择从中学习,
我总是选择从中学习。 』
『每当有人跑来跟我抱怨,
我可以选择接受抱怨
或者指出生命的光明面,
我总是选择生命的光明面。』
但并不是每件事都那么容易啊!
生命就是一连串的选择,
每个状况都是一个选择,
你选择如何回应,
你选择人们如何影响你的心情
你选择处于好心情或是坏心情
你选择如何过你的生活。
数年后
有一天,
我听到Jerry意外地做了一件
意想不到的事:
有一天他忘记关上餐厅的后门,
结果
早上,三个武装歹徒闯入抢劫,
他们要Jerry打开保险箱。
但由于过度紧张,Jerry弄错了一个号码,造成抢匪的惊慌,开枪射击Jerry
幸运地,
Jerry很快地被邻居发现,紧急送到医院抢救
经过18小时的外科手术
以及细致照顾,
Jerry终于出院了。
还有颗子弹留在他身上……
事件发生6个月之后
我遇到Jerry,
我问他最近怎么样
他回答:
『我一直都很幸福!要看看我的伤疤吗?』
我婉拒了。
但我问他当抢匪闯入的时候,他的心路历程。
Jerry答道:
『我第一件想到的事情是我应该锁后门的,当他们击中我之后,我躺在地板上,还记得我有2个选择:我可以选择生,或选择死。我选择活下去』
你不害怕吗?
Jerry继续说:
『医护人员真了不起,他们一直告诉我没事,放心。 』
『但是在他们推我去急救室路上的时候,
我看到医生跟护士脸上忧郁的神情,
我真的被吓坏了』
『他们的眼睛里好像写着:
他已经是个死人了,我知道我需要采取行动。 』
当时你做了什么?
Jerry继续说:
『当时有个挺胖的护士大声地问我,
她问我是否会对什么东西过敏?』
『我回答:有。这时医生跟护士都停下来等待我的回答。我深深地吸了一口气,』
『接着说:子弹!』
『听他们笑完之后我告诉他们:
我现在选择活下去,请把我当作一个活生生的人来开刀,不是一个活死人。 』
Jerry能活下去当然要归功于医生的精湛医术,但同时也由于他令人惊异的态度。
每天你都能选择享受你的生命,或是憎恨它。
这是唯一一件真正属于你的权利,
没有人能够控制或夺去的东西
如果你能时时注意这些愉快的事情,
现在你有两个选择:
1、你可以遗忘这故事
2、将这传递给你关心的人
我选择了2
希望你也是如此!
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
转载完毕
参加幼儿园本学期末的家长会
今天下午,去孩子幼儿园的教室里开了家长会。本来,孩子们有两位老师的,因为唐老师生病了,就只有赵老师在班上了。
先是园领导的电视讲话,主要是介绍幼儿园的教职园工状况,比较有印象的几句话是:老师都崇尚终身学习,老师的学术交流和老带新的工作比较有特色。。。
然后是赵老师介绍孩子们在园里的生活学习情况,并比较系统的讲了孩子们在中班年龄段的特点是:集体意识增强,自制能力增强。。。
还有本班孩子的一些优点和缺点,优点是孩子们都比较听话,还有行为习惯方面要加强。会上还发了家长对老师的评论表格。
我比较感兴趣的是赵老师介绍的幼儿园的新教材和一套新的幼教理论:整合式教学。大意是围绕某一项主题,在各个角度充分发挥这个主题,训练孩子在语言、数理逻辑、身体运动等各方面的能力。以“伞的世界”为例,赵老师发给我们一张“课程单元网络”图和一张“课程生成树”图,很有意思。对我们成人世界的学习也很有启发。有机会把这两张图扫描下来传上来。
这半年来,我对孩子、孩子的老师和幼儿园都比较满意。幼儿园的老师都很有爱心,很受孩子的爱戴。有时,孩子从幼儿园回来会很突然地对我们说:我以后不骂人了,骂人不是好孩子。。。我估计,老师在在幼儿园里给孩子们上了课。在这方面,我感觉老师的力量大于我们家长的作用。就我的经验而言,要想让孩子主动承认自己的错误很难。也许,是我的方法有问题。
今天,我们的孩子还得了一个表扬,与几个孩子一起被特别的提出来表扬爱收拾东西,课桌整洁。我的心里听着美滋滋的。
像赵老师讲的,孩子的行为习惯还要进一步加强。还有,我这学期对孩子的学习具体内容还关心得不够。孩子在幼儿园里具体学了些什么,以什么方式学的,学的效果怎么样,以后还要更多的关心。另外,孩子的书写能力也要加强。她喜欢画画,对这一兴趣也要更多的引导。赵老师说画画对孩子的能力培养比较有效,我表示赞同。
当然,这一切不能破坏了“快乐的童年”这一主旋律。孩子,还是以玩为主,以培养良好行为习惯为主,我以为。
附:
1)、“课程生成树”图
[img]http://java.learndiary.com/upload/2007/1/13/1168657409546_1523DtBq.jpg[/img

2)、“课程单元网络”图
[img]http://java.learndiary.com/upload/2007/1/13/1168657429984_RVqBKoUi.jpg[/img

UML建模中的状态图及状态图建模原则示例摘要(转摘)
在学习Thinking in Patterns chapter 18: Complex system states中的StateMachine的前半部分时(TIPatterns.htm#_Toc41169779),与我原来看那本System Analysis and Design中文译本中的UML建模中的状态图作了一下比较。发现二者有比较大的区别,故把状态图的有关知识再复习了一下。
下面是我在网上搜索到的一篇讲述UML状态图的文章,其中对状态图的基本定义和它在实际应用中的示例和原则都作了详细的阐述。不过比较长,而且是翻译过来的,很不好理解。尤其是前半部分讲基础概念的,更是模模糊糊的。我根据自己的需要,把上面的内容摘录了一些提纲性的东西备用。
一、基础部分
状态图(Statechart Diagram)是描述一个实体基于事件反应的动态行为,显示了该实体如何根据当前所处的状态对不同的时间做出反应的。通常我们创建一个UML状态图是为了以下的研究目的:研究类、角色、子系统、或组件的复杂行为。
状态机由状态组成,各状态由转移链接在一起。状态是对象执行某项活动或等待某个事件时的条件。转移是两个状态之间的关系,它由某个事件触发,然后执行特定的操作或评估并导致特定的结束状态。图 1 描绘了状态机的各种元素。
状态机的要素:(图 1:状态机符号。)

状态的要素:
|
转移的要素:
|
二、应用示例部分(结合示例讲了画状态图的一些准则):
我觉得文中的这个示例太好了,值得经常看看。
1、通用准则
1.1)、当行为的改变和状态有关时才创建状态图。
敏捷建模( AM) ( Ambler 2002)的原则--最大化项目干系人的投资--建议你只有当模型能够提供正面价值的时候才创建模型。
图⒈班级注册的一个UML状态图。

1.2)、把初始状态放置在左上角。
1.3)、把最终状态放置在右下角。
2、状态指南
状态是一个实体的行为模式的某个阶段。 状态的表示是通过实体的属性值。
2.1)、状态名称要简单但应具有描述性。
2.2)、避免"黑洞"状态。
2.3)、避免"奇迹"状态。
3、子状态建模指南
3.1)、为复杂的目标建模子状态。
图⒉Seminar的完整生命周期

3.2)、把通用的子状态变换放在一起
3.3)、为复杂的实体创建一个分层的状态图
图⒊Seminar的高阶状态图。

3.4)、最高阶的状态图总有初始态和最终态
4、变换和动作
变换是从一种状态到另一种状态的序列,它可能是通过一个事件触发的。
4.1)、用实现语言的命名规则命名软件动作
4.2)、只有对所有的入口变换都合适时才注明入口动作
4.3)、只有对所有的出口变换适合时才注明出口动作
4.4)、出口动作,用exit/标记来表示,工作方式类似于入口动作。
4.5)、只有当你想终止并再进入该状态时才建模递归变换
4.6)、用过去式命名转换事件
4.7)、把转换标记放在接近源状态的地方
4.8)、以转换方向为基础放置变换标记
4.9)、为了更易于判断哪个标记和变换是一起的,按照如下的规则来放置变换标记:
4.9.1)、在变换线条上的从左到右。
4.9.2)、在变换线条下的从右到左。
4.9.3)、变换线条右边的往下。
4.9.4)、变换线条左边的往上。
5、警戒点
一个警戒点是为了穿过一个转换而必须为真的一个条件。
5.1)、警戒点不应该重叠
5.2)、为可视化的定位警戒点而引入接合点。
5.3)、警戒点不必配套
5.4)、一致的命名警戒点
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
摘录完毕
Thinking in Patterns chapter 18: Complex system states
Thinking in Patterns with Java V0.9: chapter 18: Complex system states: TIPatterns.htm#_Toc41169778
1, Sections:
Complex system states 159
StateMachine. 159
Exercises. 169
Table-Driven State Machine. 169
The State class. 171
Conditions for transition. 172
Transition actions. 172
The table. 172
The basic machine. 173
Simple vending machine. 174
Testing the machine. 179
Tools. 180
Table-driven code: configuration flexibility 180
Table-driven code using anonymous inner classes 180
Exercises. 180
2, The main content and feeling:
Although I have been stopped at this chapter and State chart Diagram in UML
two or three days, there are still some questions left. But, I can't stay here
too long, there are many need to read, so, left some questions here, maybe
they will be resolved in the "future".
First of all, I found there isn't a pattern called "StateMachine Pattern" in
GoF's book except a pattern called "state pattern". Maybe, this is a design pattern invented by Bruce, just like the words below:
|
What is Bruce's "StateMachine Pattern"?
He tells us:
|
There are two types of "StateMachine Pattern" implementation in this book.
The first is called "StateMachine" simplily, and second is called "Table-Driven State Machine". When I read these two "statemachine", I compared them with the State chart Diagram in UML I have learned before. So I found some question I can't answer. Below is my understanding for these two Bruce's StateMachine.
At first, give my understanding about State chart Diagram in UML, I like its
OOP style, even I maybe missunderstood it, I put my understanding here, wish
someone can point out my error.
A State chart Diagram can be owned by an entity(for example, an object of a
class ), if the entity's action dependents on what state the entity is in, then a state chart diagram may be needed.
For me, the most important understanding about this is the transition between
two states. Three things can be in a transition: event, just a call to this
object's method or a message send to this object; guard condition, only it is
"true" can event cause a state's change; action, just some processes in
object's method or some messages send to other objects to perform somethings during this transition.
Then, bring the idea of UML's state chart diagram in my mind, I look at Bruce's first "StateMachine".
In this statemachine, all is focus on the state class. state class performace
some actions in the transition SHOULD before this state, state class recieve an input
and decide which state is the next state.
Just like below:
|
Why do I say "state class performace some actions in the transition SHOULD before this state"?
Because I read some in this book like below:
|
I try to model the example of "statemachine" with UML's state chart diagram,
but I failed. Because the state object has done all the things, and the owner of
state objects has nothing to do. I can't send the owner a message which should
be a method of the owner to make a transition!
And another question in the example is:
|
Why is "Waiting: Broadcasting cheese smell" in the run() method, but not
"Wait: Broadcast cheese smell"? Does it indicate a state or an action during transition before this state? I am a little confusing.
And, from the State chart diagram's definition, an action should be occured
before current state appeared in this example, but I don't know why it happens
as a run() method in a state object, just like below:
|
Next, from section "Table-Driven State Machine" I can draw example's State
chart Diagram using UML tool.
In this example, the state class can't do something like above's example, and,
an object called stateMachine holds every thing. I can send this stateMachine
a message: nextState(input: Input), this just a event cause the state's
change; And, when this transition is made, an action occurs by nextState()
to call another object's method: Transition.transition(input: Input), or the
stateMachine object just send a message to trasition object to do some actions.
Maybe, this just is the meaning of Bruce's words: "The classic state-transition diagram".
Maybe, Bruce's statemachine is from the aspect of using purpose, all these examples are focusing on how to design a statemachine conveniently; But I focus on if these "statemachine" are real "StateMachine" defined in UML.
Maybe, I have misunderstood all the UML's "statemachine" and the
"statemachine" in this book's example. If any of these case, please give me a
hint. My english is also very poor, if there are some thing unclear, please
let ne know. Thanks.
3, Questions about programming:
Many questions has been written above. Except above, There are entire section
I can't understand just below:
|
And, I almost can't see the picture after this section.
4, Questions about english language:
1), Strange words:
impose, tagging, conceivably, mousetrap, theWhiW,
2), Strange sentences:
// A State has an operation, and can be moved
// into the next State given an Input:
This is typical, but certainly not required ? you could concievably want to override it, but typically the behavior change will occur in State?s run( ) instead.
incomplete
Thinking in Patterns chapter 17: Multiple languages
Thinking in Patterns with Java V0.9: chapter 17: Multiple languages: TIPatterns.htm#_Toc41169757
1, Sections:
Multiple languages 120
Interpreter motivation. 121
Python overview.. 122
Built-in containers. 123
Functions. 124
Strings. 125
Classes. 127
Creating a language. 130
Controlling the interpreter. 134
Putting data in. 134
Getting data out. 140
Multiple interpreters. 143
Controlling Java from Jython 144
Inner Classes. 148
Using Java libraries. 148
Inheriting from Java library classes 150
Creating Java classes with Jython 151
Building the Java classes from the Python code 156
The Java-Python Extension (JPE) 157
Summary. 157
Exercises
2, The main content and feeling:
First at all, let me remember a fact, this book is written at 3 years ago,
too many changes has been taken, so I think the language Python introduced
by Bruce in this book has many changes. And, there are many kinds of other languages maybe has present.
Then, let us see what has been told in this chapter.
At last, two days' reading without installing Python or Jython, I get a
conclusion: Python, maybe is the best lovely program language of Bruce's. The
most part of this chapter is introducing Python. On the other hand, the Interpreter Pattern in this Design patterns book is a little part of this chapter.
What is Interpreter Pattern?
It says:
|
Note, although in almost all applications there are some factors that end
user can change it by some ways, for example, input something or press some
buttons, etc.. But, in a interpreter pattern, it provides end users the most probability for custom there many factors by simple programming.
And, a ready for use this kind of Interpreter system introduced by Bruce is
Jython, a pure Java implementation of Python language. Of course, you can
write your own Interpreter sytem. But it seems too unecessary.
Along with Bruce's lines, I got some about Python and Jython, and this is
almost real the first touch of this language for me. I can understand little
bit of examples in this book without to run it under *ython.
Use some sentences in this book to summary the understanding for *ython of
mine.
|
|
...
If you program with *ython, no redundant charactor typing. And it can be
worked together with java very well. All the Jython class and Java class can
almost interact without any problem. And, if you need native Python program
interact with Java, a resolution called The Java-Python Extension (JPE) can be
used.
In this book, Bruce says maybe a new Design Pattern called Multiple Language
can be invented. In this way, mixing languages to resolve a question can be
better than using only one language. All the languages has its advantage and
shortage, mix them is a good idea.
Bruce says:
|
But, I doubt that "5-10 times faster than C++ or Java", although I am not a
professional programmer(I don't work in IT), I think it is impossible that a
language has 5-10 times development speed than others. Because, building an
application need not only coding, but also many other works. I suppose, Python is good at coding, at building a good classes system, but, what classes are we need? How do they interact with each other? etc.. These kind of things is can't be reduced many only by a language.
But, maybe, "Python?s extremely rapid development" is only refer to coding,
and mix this coding process with "Java's architecture" which is good at
building system architecture.
3, Questions about programming:
1), if you create fields using the C++/Java style, they implicitly become static fields.
2),
In addition, Jython’s JavaBean awareness means that a call to any method with a name that begins with “set” can be replaced with an assignment, as you can see above.
You are not required to inherit from Object; any other Java class will do.
Note that it?s important that the directory where the target lives be specified, so that the makefile will create the Java program with the minimum necessary amount of rebuilding.
4, Questions about english language:
1), Strange words:
advantageous, arbitrarily, stuck, tedious, Interpreter, distraction, for-profit, royalties, basically, incorporating, scales up, purity, referred to, marvelous, affirmative, subsequent, add-on, acknowledged, associative, formalize, takes on, imitate, verbiage, signature, other than, tuple, control over, decimal place, spare, set off, turns out to be, aggressively, albeit, penchant, comma, from within, deceptively, thorough, further down, ambiguous, back and forth, it is worth noting that, disposal, endearing, intuitively, awareness, automated, shorthand, presumably,
come over, lambda, succinct, hood, frustrating, stem from, arguably, lurking,
potent, flesh out, terrific, leverage
2), Strange sentences:
Indenting can nest to any level, just like curly braces in C++ or Java, but unlike those languages there is no option (and no argument) about where the braces are placed the compiler forces everyone’s code to be formatted the same way, which is one of the main reasons for Python’s consistent readability.
Note that Python was not named after the snake, but rather the Monty Python comedy troupe, and so examples are virtually required to include Python-esque references.
incomplete
Thinking in Patterns Chapter 16: Complex interactions
Thinking in Patterns with Java V0.9: Chapter 16: Complex interactions: TIPatterns.htm#_Toc41169753
1, Sections:
Externalizing object state 113
Memento. 113
Complex interactions 114
Multiple dispatching. 114
Visitor, a type of multiple dispatching 117
Exercises
2, The main content and feeling:
Memento Pattern isn't described in this book(So I don't write a diary of Chapter 16: Externalizing object state), I must learn it in other place.
After twice reading of chapter: Complex interactions, I got little from the book. Don't like Thinking in Java, in that book, there is detail explaination after every example. But, it isn't given explaination in this chapter's two examples. This book is only Version0.9.
1), What is Multiple dispatching? I knew it from this point: "Remember that polymorphism can occur only via member function calls, if you want double dispatching to occur, there must be two member function calls: the first to determine the first unknown type, and the second to determine the second unknown type."
Just describe it use the example in the book below:
|
|
Here, a scissors vs. a paper:
s Item = new Scissors();
p Item = new Paper();
s.compete(p); // the first(method compete()) to determine the first unknown type(Scissors),
//In the method "compete()", the second method is called
p.eval(s);// the second(method eval()) to determine the second unknown type(Paper),
Why does the first(method compete()) NOT to determine the second unknown type(Paper)?
The key is this statement above:
polymorphism can occur only via member function calls
When the method compete() be called, the type of the object that call this method is determined, "Item" "s" is a "Scissors".
The second method eval() is same as the first method complete().
2), Visitor, a type of multiple dispatching
After know the Mutiple dispatching, Vistor Pattern is understood soon. Because, it "builds on the double dispatching scheme shown in the last section".
There is a point need to note, the purpose of using Vistor Patterns is changing the method's behavior without modifying original hierarchy.
I explain this using the example in the book too:
In this example, Flower classes hierarchy can't be changed. And can determining it's type by calling it's method: accept(Visitor v);
Although Flower classes herarchy can't be changed, but Visitor classes herarchy can be changed, so there are two types of Visitor be created, one is "StringVal", another is "Bee". And, the second Type be determined in this method below:
v.visit(this); //"this" is a Flower, when the "v" call visit() method, its type be termined. And, different type Vistor visit(this) can get different behavior, that just we want to get.
3), Multiple dispatching can be replaced by a table lookup, just look it in the exercise 3.
I think there are two type of Map will be used. it is one: key is class, value is another map; another map: key is class, value is outcome.
4), At this point, I suddenly think, I guess, Bruce thinks the Design Pattern isn't a very import thing in his software design, I feel his words outside this book is just saying: many of these "Dsign Patterns" is redundant, a basic idea of mine be divided into these too many Patterns, this basic idea is: No pattern is patterns for all.
This is only my guess, my feeling. If my feeling is right, maybe, we maybe can't see a version1.0 of this book:(
My english language and program knowledge is poor, if I make any mistake, please tell me: mdx-xx@tom.com
3, Questions about programming:
1), The answer starts with something you probably don’t think about: Java performs only single dispatching. That is, if you are performing an operation on more than one object whose type is unknown, Java can invoke the dynamic binding mechanism on only one of those types. This doesn’t solve the problem, so you end up detecting some types manually and effectively producing your own dynamic binding behavior.
2), How to do if there are more than double dispatching in the above?
Like below?
a.F(b);
b.G(c);
c.H(a);
...
3), All the exercises.
4, Questions about english language:
1), Strange words:
compete, Scissors, Outcome, primary, dilemma, virtualize, bound, Gladiolus, Runuculus, Chrysanthemum, Inhabitant, Dwarf, Elf, Troll, Jargon, InventFeature,
Each Inhabitant can randomly produce a Weapon using getWeapon( ): a Dwarf uses Jargon or Play, an Elf uses InventFeature or SellImaginaryProduct, and a Troll uses Edict and Schedule.
syntactic, simplicity,
2), Difficult sentences:
The easiest way to do this is to create a Map of Maps, with the key of each Map the class of each object.
******************************************************************
The class diagrams of two examples in the book:
1),//: multipledispatch:PaperScissorsRock.java

2),//: visitor:BeeAndFlowers.java

incomplete
Googlebot和 Mediapartners-Google 抓取报告中的怪事
Googlebot是google搜索抓取机器人,而Mediapartners-Google是为显示相关广告而抓取网页的机器人。
这几天,在Googlebot的抓取报告中出现这样的莫名其妙的字眼:
|
而在Mediapartners-Google的抓取报告中出现莫名其妙的robots.txt拦截网址,问题是我在robots.txt中根本就没有拦截这些网址:
|
截图分别如下:
1)、Googlebot的抓取报告

2)、Mediapartners-Google的抓取报告

Thinking in Patterns Chapter 14: Algorithmic partitioning
Thinking in Patterns with Java V0.9: Chapter 14: Algorithmic partitioning: TIPatterns.htm#_Toc41169746
1, Sections:
Algorithmic partitioning 106
Command: choosing the operation at run-time 106
Exercises. 109
Chain of responsibility. 109
Exercises
2, The main content and feeling:
1) Command pattern:
It is "wrapping a method in an object". From my understanding, a Command is a very simple class with a sole method to resolve a specific task. When I perform a big task, I can put some of these Command objects together, and in a "manager" class, call these object's own sole method to perform its specific little task, and, in this way, to finish that big task through these little object's contributions.
In my first touch of these patterns, I think there are clear differents between Command Pattern and Strategy Pattern:
Command Pattern: Put serveral Command objects together to perform a common task, just like draw together to fight on a common enemy;
Strategy Pattern: At a specific time use a specific Strategy to accomplish a different result.
But, why does Bruce say below in the book:
|
Maybe, Bruce describe it from the structural aspect, I look at them at the function's aspect.
2) Chain of Responsibility:
That just an "Expert System", there are several experts in this system, and, these experts wait here in line. When a problem come, from the first expert to the last expert, every expert try to resolve this problem. If one can't do it, then the problem be handed to the next expert, until the problem be rosolved or the last expert can't do it yet, then an un-resolved problem is retruned.
From this view aspect, Chain of Responsibility just like an auto-selected Strategy Pattern: the method for resolving problem is auto selected in the former, and a manual-selected strategy used for a problem in the later.
A question raises, what if the problem handed to the Expert System need serveral experts to resolve them respectively? Maybe, this problem need to be cuted into serveral little problems then hand them into the expert system successively.
In this pattern, Bruce says GoF use many words to create an linked list to contain these "experts", it is because GoF wrote that Design Pattern at the time "before the Standard Template Library (STL) was incorporated into most C++ compilers'. But, in Java, a ready-made List is here.
In fact, I need review these content when I finish the first reading of this book. So, although there are some place I can't understand it very clearly, but, I must go on, finish the first reading of entire book in shortest time is the most import thing. I just only read half of this book. After reading this book once, the J2EE Design Patterns need me to read. So, don't tie at any specific point, go! go! go!
3, Questions about programming:
1), The point is to decouple the choice of function to be called from the site where that function is called.
2), something you can normally only do by writing new code but in the above example could be done by interpreting a script.
3), What is the famous "callback" technique?
4, Questions about english language:
1), Strange words:
functor, collectively, incorporated into, BabelFish, Bisection, ConjugateGradient, fragile
2), Difficult sentences:
On the other hand, with a Command object you typically just create it and hand it to some method or object, and are not otherwise connected over time to the Command object.
********************************************************************************************************
Class diagram of //: chainofresponsibility:FindMinima.java in section: Chain of responsibility

incomplete