Thinking in Patterns with Java V0.9: chapter 6: Factoring commonality: TIPatterns.htm#_Toc41169707
1, The sections name of today's learning;
Strategy: choosing the algorithm at run-time 48
Policy: generalized strategy. 50
Template method. 50
Exercises
2, What is it talk about in these sections and comments and feeling for the content:
the “once and only once” principle, said at the begin of this chapter, I can't know it's meaning very clear, is it saying: do only one thing in a method?
And, State, Strategy, Policy, Template method, it seems to me these four patterns has very similiar character, I can't distinguish them very clear.
1), Strategy: choosing the algorithm at run-time
However, I haven't find there is any difference bwteen State and Strategy now except their names. class ServiceProvider in state:StateDemo.java just like class MinimaSolver in strategy:StrategyPattern.java, and so on.
2), Policy: generalized strategy.
No example in this section, it just says:"It also seems generally useful to distinguish Strategies with single methods from Policies with multiple methods."
3), Template method.
What is Template method?
From my understanding, there exist two definitions : one is Template method Patterns; and another is a specific method in a base class, the mothod is usually called by the initialization method of this base class (I can't know if it is always called by that initialization method), this template method then call other methods in the base class to perform some actions, these performing real actions' methods can be overridden by the derived class.
Although it says:"Note similarity with template method ? TM claims distinction that it has more than one method to call, does things piecewise. However, it?s not unlikely that strategy object would have more than one method call;" I can't feel there are too many similar places between State pattern and Template method pattern. Maybe, after reviewing this book, I will change my feeling a lot.
I have found a bit difficult to learn this book, and write the diary in
english is a bit difficult too, if the difficult degree over my knowledge
scope a lot, maybe I will seek another resource to learn Design Patterns,
maybe a chinese book is better for me?
3, My questions about the program itself;
1), Can't understand: Applying the "once and only once" principle produces the most basic pattern of putting code that changes into a method.
2), The difference between State and strategy pattern;
3), Policy's example
4), The difference between State and Template method.
4, My questions about the english language;
1), Strange words:
factoring commonality, similarity, piecewise, piecewise, shallowway, fulfullment, Policy, generalized, customs, undetermined,
2), Strange sentences:
1>, A fundamental concept in the application framework is the Template Method which is typically hidden beneath the covers and drives the application by calling the various methods in the base class (some of which you have overridden in order to create the application).
*****************************************************************************************************
//: strategy:StrategyPattern.java
//Strategy: choosing the algorithm at run-time
incomplete
"Factoring commonality", this just is a mathematics concept.
factoring: 1. (mathematics) the resolution of an integer or polynomial into factors such that when multiplied together they give the integer or polynomial.
commonality: sharing of common attributes
example(gotten from google searching result by searching keyword"factoring commonality"):
Axion utilizes commonality factoring technology to eliminate the redundancy caused by each of the factors above to drastically reduce the amount of data that must be backed up and managed.
Then, think together with this chapter's context, I know this concept at last: it is alway a base concept of design program and this concept which Bruce had come up with it again and again, that is seperating the unchange and change, put the "unchange" into a common part, and the "change" into another method.
speaking it in chinese like this: 分解公共因子
Maybe, I am right:)