Collecting Parameter,TestResult中称其为Collecting Parameter Pattern。我觉得它更象个Idiom。
这在Struts的org.apache.struts.taglib.*中有非常广泛的应用,随便选个示例如下:
public int doStartTag() throws JspException {
// Create an appropriate "input" element based on our parameters
StringBuffer results = new StringBuffer("<input type=\"checkbox\"");
prepareAttribute(results, "name", prepareName());
prepareAttribute(results, "accesskey", getAccesskey());
prepareAttribute(results, "tabindex", getTabindex());
prepareAttribute(results, "value", getValue());
if (isChecked()) {
results.append(" checked=\"checked\"");
}
results.append(prepareEventHandlers());
results.append(prepareStyles());
prepareOtherAttributes(results);
results.append(getElementClose());
// Print this field to our output writer
TagUtils.getInstance().write(pageContext, results.toString());
// Continue processing this page
this.text = null;
return (EVAL_BODY_TAG);
}
其中的StringBuffer results =... ...就是所说的Collecting Parameter。
这个示例源于org.apache.struts.taglib.html.CheckboxTag,可以在Apache.org下载到源代码。
Move Accumulation to Collecting Parameter从重构的角度对Collecting Parameter进行了较好的说明,照抄如下([]中的文字为我们所添加的注释):
You have a single bulky method that accumulates information to a local variable. [重构前]
Accumulate results to a Collecting Parameter that gets passed to extracted methods. [重构后]
[重构过程的图示如下:]
JUnit is a regression testing framework written by Erich Gamma and Kent Beck. It is used by the developer who implements unit tests in Java. 源于:JUnit.org。
译文:JUnit是由Erich Gamma和Kent Beck完成的回归测试框架。Java开发人员可以用它来实现单元测试。
JUnit中最关键的抽象就是Test,它有两个重要的子类TestSuite和TestCase。
JUnit.org上有丰富的资源:
阅读了上面的富有价值的内容之后发现其中没有对JUnit运行时的时序和对运行时的对象状态的描述,因此我们构建了一个典型的场景并试图描述这两个方面,如下:
这之后的内容基于JUnit3.8.2,可以在JUnit.org下载到该软件包。
我们先给出两段源代码,分别表示AllTests和WordTest,随后给出这两段代码的时序图和对象图。其中的代码只包括骨架。
AllTests类的源代码,如下:
package org.solol.test;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* @author solo L
*
*/
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test Suite");
suite.addTestSuite(WordTest.class);
return suite;
}
}
WordTest类的源代码,如下:
package org.solol.test;
import junit.framework.TestCase;
/**
* @author solo L
*
*/
public class WordTest extends TestCase {
protected void setUp() throws Exception {
}
protected void tearDown() throws Exception {
}
public final void testWord() {
}
public final void testGetLength() {
}
public final void testGetValue() {
}
}
时序图,如下:
对象图,如下: