你有两个选择(转自朋友的邮件)

转载者前言:

太多的时候,我们都不能改变客观环境,但我们可以自由的改变思考的角度和主观心情。我觉得,人生快乐与否很大程度上取决于自己是否会进行选择:您可以选择快乐,也可以选择痛苦。就这么简单。

转帖正文,后附朋友发送的ppt演示文档。在此感谢这位朋友发来这么好的东西。并与所有朋友分享。

×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××

Jerry是美国一家餐厅的经理,他总是心情非常好,

当别人问他最近过得如何时,

他总是有好消息同大家说。

他总是回答:

『我一直都很幸福!』

当他换工作的时候,

许多服务生都跟着他

从这家餐厅换到另一家。

为什么呢?

因为Jerry是个天生的激励者!

如果有某位员工今天运气不好,

Jerry总是适时地告诉那位员工

往好的方面想。

看到这样的情境,真的让我很好奇,所以有一天我到Jerry那儿问他:

我不懂,没有人能够老是那样地积极乐观,你是怎么办到的?

Jerry回答:

『每天早上,当我起来的时候我告诉自己:

我今天有两种选择 ,

我可以选择好心情,

或者我可以选择坏心情。

 

我总是选择好心情』

『即使有不好的事发生,

我可以选择做个受害者,

或是选择从中学习,

我总是选择从中学习。 』

『每当有人跑来跟我抱怨,

 我可以选择接受抱怨

或者指出生命的光明面,

我总是选择生命的光明面。』

但并不是每件事都那么容易啊!

   生命就是一连串的选择,

每个状况都是一个选择,

你选择如何回应,

你选择人们如何影响你的心情

你选择处于好心情或是坏心情

   你选择如何过你的生活。

数年后

有一天,

我听到Jerry意外地做了一件

意想不到的事:

有一天他忘记关上餐厅的后门,

结果

早上,三个武装歹徒闯入抢劫,

他们要Jerry打开保险箱。

但由于过度紧张,Jerry弄错了一个号码,造成抢匪的惊慌,开枪射击Jerry

幸运地,

Jerry很快地被邻居发现,紧急送到医院抢救

经过18小时的外科手术

以及细致照顾,

Jerry终于出院了。

还有颗子弹留在他身上……

事件发生6个月之后

我遇到Jerry,

我问他最近怎么样

他回答:

『我一直都很幸福!要看看我的伤疤吗?』

我婉拒了。

但我问他当抢匪闯入的时候,他的心路历程。

Jerry答道:

『我第一件想到的事情是我应该锁后门的,当他们击中我之后,我躺在地板上,还记得我有2个选择:我可以选择生,或选择死。我选择活下去』

你不害怕吗?

 Jerry继续说:

『医护人员真了不起,他们一直告诉我没事,放心。 』

『但是在他们推我去急救室路上的时候,

我看到医生跟护士脸上忧郁的神情,

我真的被吓坏了』

『他们的眼睛里好像写着:

他已经是个死人了,我知道我需要采取行动。 』

   当时你做了什么?

Jerry继续说:

『当时有个挺胖的护士大声地问我,

她问我是否会对什么东西过敏?』

『我回答:有。这时医生跟护士都停下来等待我的回答。我深深地吸了一口气,』

 『接着说:子弹!』

 『听他们笑完之后我告诉他们:

我现在选择活下去,请把我当作一个活生生的人来开刀,不是一个活死人。 』

Jerry能活下去当然要归功于医生的精湛医术,但同时也由于他令人惊异的态度。

每天你都能选择享受你的生命,或是憎恨它。

这是唯一一件真正属于你的权利,

没有人能够控制或夺去的东西

                    

如果你能时时注意这些愉快的事情,

现在你有两个选择:

1、你可以遗忘这故事

2、将这传递给你关心的人

      我选择了2

   希望你也是如此!

附件:你有两个选择.ppt,86528 bytes

×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××

                                            转载完毕

参加幼儿园本学期末的家长会

今天下午,去孩子幼儿园的教室里开了家长会。本来,孩子们有两位老师的,因为唐老师生病了,就只有赵老师在班上了。

先是园领导的电视讲话,主要是介绍幼儿园的教职园工状况,比较有印象的几句话是:老师都崇尚终身学习,老师的学术交流和老带新的工作比较有特色。。。

然后是赵老师介绍孩子们在园里的生活学习情况,并比较系统的讲了孩子们在中班年龄段的特点是:集体意识增强,自制能力增强。。。

还有本班孩子的一些优点和缺点,优点是孩子们都比较听话,还有行为习惯方面要加强。会上还发了家长对老师的评论表格。

我比较感兴趣的是赵老师介绍的幼儿园的新教材和一套新的幼教理论:整合式教学。大意是围绕某一项主题,在各个角度充分发挥这个主题,训练孩子在语言、数理逻辑、身体运动等各方面的能力。以“伞的世界”为例,赵老师发给我们一张“课程单元网络”图和一张“课程生成树”图,很有意思。对我们成人世界的学习也很有启发。有机会把这两张图扫描下来传上来。

这半年来,我对孩子、孩子的老师和幼儿园都比较满意。幼儿园的老师都很有爱心,很受孩子的爱戴。有时,孩子从幼儿园回来会很突然地对我们说:我以后不骂人了,骂人不是好孩子。。。我估计,老师在在幼儿园里给孩子们上了课。在这方面,我感觉老师的力量大于我们家长的作用。就我的经验而言,要想让孩子主动承认自己的错误很难。也许,是我的方法有问题。

今天,我们的孩子还得了一个表扬,与几个孩子一起被特别的提出来表扬爱收拾东西,课桌整洁。我的心里听着美滋滋的。

像赵老师讲的,孩子的行为习惯还要进一步加强。还有,我这学期对孩子的学习具体内容还关心得不够。孩子在幼儿园里具体学了些什么,以什么方式学的,学的效果怎么样,以后还要更多的关心。另外,孩子的书写能力也要加强。她喜欢画画,对这一兴趣也要更多的引导。赵老师说画画对孩子的能力培养比较有效,我表示赞同。

当然,这一切不能破坏了“快乐的童年”这一主旋律。孩子,还是以玩为主,以培养良好行为习惯为主,我以为。

附:

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:状态机符号。)

  状态的要素:


名称:            将一个状态与其他状态区分开来的文本字符串;状态也可能是匿名的,这表示它没有名称。

进入/退出操作:    在进入和退出状态时所执行的操作。

内部转移:        在不使状态发生变更的情况下进行的转移。

子状态:          状态的嵌套结构,包括不相连的(依次处于活动状态的)或并行的(同时处于活动状态的)子状态。

延迟的事件:      未在该状态中处理但被延迟处理(即列队等待由另一个状态中的对象来处理)的一系列事件。

  转移的要素:


源状态:            转移所影响的状态;如果对象处于源状态,当对象收到转移的触发事件并且满足警戒条件(如果有)时,就可能会触发输出转移。

事件触发器:        使转移满足触发条件的事件。当处于源状态的对象收到该事件时(假设已满足其警戒条件),就可能会触发转移。

警戒条件:          一种布尔表达式。在接收到事件触发器而触发转移时,将对该表达式求值;如果该表达式求值结果为 True,则说明转移符合触发条件;如果该表达式求值结果为 False,则不触发转移。如果没有其他转移可以由同一事件来触发,该事件就将被丢弃。

操作:              可执行的、不可分割的计算过程,该计算可能直接作用于拥有状态机的对象,也可能间接作用于该对象可见的其他对象。

目标状态:          在完成转移后被激活的状态。

二、应用示例部分(结合示例讲了画状态图的一些准则):

  我觉得文中的这个示例太好了,值得经常看看。

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:


This method not only moves to the next state, but it also calls run( ) for each state object ? thus you can see it?s an expansion of the idea of the State pattern, since run( ) does something different depending on the state that the system is in.

What is Bruce's "StateMachine Pattern"?

He tells us:


While State has a way to allow the client programmer to change the

implementation, StateMachine imposes a structure to automatically change the

implementation from one object to the next.

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:


public interface State {

  void run();

  State next(Input i);

} ///:~

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:


 and as that transition is made some kind of action occurs (in the previous state machine design, this was the run( ) method):

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:


class Waiting implements State {

  public void run() {

    System.out.println(

      "Waiting: Broadcasting cheese smell");

  }

  public State next(Input i) {

    MouseAction ma = (MouseAction)i;

    if(ma.equals(MouseAction.appears))

      return MouseTrap.luring;

    return MouseTrap.waiting;

  }

}

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:


  public final void runAll(Iterator inputs) {

    while(inputs.hasNext()) {

      Input i = (Input)inputs.next();

      System.out.println(i);

      currentState = currentState.next(i);

      currentState.run();

    }

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:


(Simple State Machine Diagram)

Goals:

·         Direct translation of state diagram

·         Vector of change: the state diagram representation

·         Reasonable implementation

·         No excess of states (you could represent every single change with a new state)

·         Simplicity and flexibility

Observations:

·         States are trivial – no information or functions/data, just an identity

·         Not like the State pattern!

·         The machine governs the move from state to state

·         Similar to flyweight

·         Each state may move to many others

·         Condition & action functions must also be external to states

·         Centralize description in a single table containing all variations, for ease of configuration

Example:

·         State Machine & Table-Driven Code

·         Implements a vending machine

·         Uses several other patterns

·         Separates common state-machine code from specific application (like template method)

·         Each input causes a seek for appropriate solution (like chain of responsibility)

·         Tests and transitions are encapsulated in function objects (objects that hold functions)

·         Java constraint: methods are not first-class objects

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:

 


  Sometimes the end users of your application (rather than the programmers of

that application) need complete flexibility in the way that they configure

some aspect of the program. That is, they need to do some kind of simple

programming. The interpreter pattern provides this flexibility by adding a

language interpreter.

 

  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.

 


Python is a language that is very easy to learn, very logical to read

and write, supports functions and objects, has a large set of available

libraries, and runs on virtually every platform.

 

 


 It is marvelous for scripting, and you may find yourself

replacing all your batch files, shell scripts, and simple programs with Python

scripts. But it is far more than a scripting language.

 

 ...

 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:

 


  To me, Python and Java present a very potent combination for program

development because of Java?s architecture and tool set, and Python?s

extremely rapid development (generally considered to be 5-10 times faster than C++ or Java).

 

  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:


class Scissors implements Item {

  public Outcome compete(Item it) { return it.eval(this); }

  public Outcome eval(Paper p) { return Outcome.LOSE; }

  // ...

}


class Paper implements Item {

  public Outcome compete(Item it) { return it.eval(this); }

  public Outcome eval(Paper p) { return Outcome.DRAW; }

  //..

}

  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的抓取报告中出现这样的莫名其妙的字眼:


我们已成功访问您的主页。

-----------------------------------------------------------

restriction. not be translated.

而在Mediapartners-Google的抓取报告中出现莫名其妙的robots.txt拦截网址,问题是我在robots.txt中根本就没有拦截这些网址:


        已拦截网址      拦截原因  [?]    上一次抓取尝试     尝试失败

  http:/ / 209. 85. 165. 104/ search? q= cache:hIzBannSd6wJ:java. learndiary. com/ diaries/ 1367. jsp+error+1045+access+denied+for+user+root%40localhost&hl= zh-CN&gl= us&ct= clnk&cd= 7 Robots.txt 文件 2006-12-29 1

  http:/ / 64. 233. 161. 104/ search? q= cache:tvsE7YLr87kJ:java. learndiary. com/ diaries/ 1481. jsp+hibernate+spring&hl= zh-CN&gl= us&ct= clnk&cd= 128 Robots.txt 文件 2006-12-27 1

截图分别如下:

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:

 


 I would hazard to say that Command provides flexibility while you’re writing the program, whereas Strategy’s flexibility is at run time. Nonetheless, it seems a rather fragile distinction.

 

 

  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

让孩子唱孩子应该唱的,玩孩子应该玩的吧

今天,有两个事情使我要写这篇日记。

1、某处元旦节庆祝。其中有两个小学二三年级的孩子唱歌和跳舞,唱的是S.H.E的《不想长大》,歌词是这样的:


...

我不想我不想不想长大

长大后世界就没有花

我不想我不想不想长大

我宁愿永远又笨又傻

我不想我不想不想长大

长大后我就会失去他

我深爱的他深爱我的他

已经变的不像他

...

完整的见:

http://mp3.baidu.com/m?tn=baidump3lyric&word=%B2%BB%CF%EB%B3%A4%B4%F3&ct=150994944&lm=-1&lf=3

其中一个还跳着很成人的舞姿。

相反,有个成人上台表演跳的是很传统的蒙古草原舞蹈。

2、女儿让我给她买一种贴纸画,我不知道是哪种(后来知道是泡泡糖里的),就看了另外的贴纸画,清一色的是武侠小说里的人物:好像有:小龙女,小李飞刀什么的。听店主说,这种贴纸卖得很好。这个小店就紧挨着一个幼儿园。

而且,我想起现在许多小孩都在唱不是他们该唱的歌,看不是他们该看的漫画(尤其是有些日本的卡通漫画),这让我很想说:让孩子唱孩子应该唱的,玩孩子应该玩的吧。

在我的心里,孩子的世界应该是童话的、纯洁的世界。里面有灿烂的阳光、蓝蓝的天、绿绿的草、五颜六色的花,还有蝴蝶等。。。

但是,现实是严竣的,以上两个小事只是冰山一角。

难道,我们找不到给孩子唱的,给孩子玩的吗?我不这样认为。而且,我也不认为,孩子们就只有看外国动画、漫画(这段时间我们的孩子嘴里常念叨的是什么:奥特曼、迪克、超人、怪兽;葫芦娃也有提,时候不多;我想,我们从来没有给她看这些,一定是她的小朋友圈子中互相交流的热门主题,哪个最英雄,我要当奥特曼、超人,打怪兽...)。我们的血液里天生有一份最值钱的祖宗留下的、世界仅有的宝贵财富:5000年厚重的文化传承,这一点也可以说,中国人是世界最富有的人,我们应该为生为中国人而骄傲。

难道,这悠悠5000年的文化还找不到怎样来滋润孩子心灵的灵感和源泉吗?不会吧。我们完全可以以现代的科技,随便在5000年的历史长河中捡一点,就能做出至少是中国的唐老鸭和米老鼠,进一步,做成世界级的东西也不是没有可能。我们的东西有不少是外国人在发挥,像日本的三国文化(包括:游戏、漫画等),美国的花木兰,当然,应该还有太多,不过我没有去找,如果是专心去找,肯定有不少的。

作为一个家长、孩子的父亲,我希望我们的孩子能够唱他们该唱的、玩他们该玩的、看他们该看的。

linux下的换行符号引起Resin3的struts-config.xml解析报错

由于linux和windows的换行符不一致,有时在这种系统间的文件交换就会出现问题。我就碰到这样的问题。

本来应该是这样的Struts-config.xml内容:


        <action

            attribute="loginForm"

            input="/login.jsp"

            name="loginForm"

            path="/loginAction"

            type="com.learndiary.website.action.account.LoginAction">

            <forward name="success" path="/loginSuccess.jsp" />

            <forward name="failure" path="/login.jsp" />

        </action>

可能是从windows转到linux下变成了这样:


        <action^M^M

            attribute="loginForm"^M^M

            input="/login.jsp"^M^M

            name="loginForm"^M^M

            path="/loginAction"^M^M

            type="com.learndiary.website.action.account.LoginAction">^M^M

            <forward name="success" path="/loginSuccess.jsp" />^M^M

            <forward name="failure" path="/login.jsp" />^M^M

        </action>

这在本地的Tomcat5和空间原来的Resin2下都没有问题,但是当空间改为Resin3后,每次重新启动应用就报错:


The content of element type "action" must match "(icon?,display-name?,description?,set-property*,exception*,forward*)".

...

但是奇怪的是,应用启动后的工作看起来还是正常的。

下面附的是相关的文字:(转自:http://www.real-blog.com/linux-bsd-notes/67

Unix 及 Windows 文字檔轉換

大家如果試過在 Linux 及 Windows 文字檔分享的話,會發現文字檔的 “換行” 不一樣。在 Windows 用記事本開啟 Unix 文字檔時,文件不會開新行,需要使用支援 Unix 格式的文字編輯器才可看到分行;而在 Linux 開啟 Windows 的文字檔時,在每一行最後會有字元 Ctrl-m (^M)。以下是使用 Perl 在 Linux 下將文字檔轉換的方法:

Windows 格式 -> Unix 格式

perl -p -e ’s/\r$//’ < winfile.txt > unixfile.txt

Unix 格式 -> Windows 格式

perl -p -e ’s/\n/\r\n/’ < unixfile.txt > winfile.txt

February 13, 2006 · Linux / BSD 筆記, Windows 筆記 ·

1 Comment »

   1.

      UNIX WINDOWS MAC三者的回车都不一样,好像是:windows是0×0d 0×0a

      UNIX是0×0d MAC是0×0a吧。记不太清楚了。大体上是这样的。

      Comment by 数据恢复 — April 6, 2006 @