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