0%

类型 Type

  • 创建型 Creational

含义 Intent

The intent of the factory method pattern is to define an interface for creating an object, but to let subclasses decide which class to instantiate. Factory method lets a class defer instantiation to subclasses.

阅读全文 »

类型 Type

  • 创建型 Creational

含义 Intent

The intent of the singleton pattern is to ensure that a class only has one instance, and to provide a global point of access to it.

阅读全文 »

短小 Small

函数的第一条规则是要 短小,第二条规则是要 更短小

  • 20 行封顶最佳

例子:

1
2
3
4
5
6
7
public static String renderPageWithSetupsAndTearDowns(PageData pageData, boolean isSuite) throws Exception
{
if (isTestPage(pageData)) {
includeSetupAndTeardownPages(pageData, isSuite);
}
return pageData.getHtml();
}
阅读全文 »

名副其实 Use Intention-Revealing Names

如下是较好的例子(既有计量对象,也有计量单位):

1
2
3
4
int elapsedTimInDays;
int daysSinceCreation;
int daysSinceModification;
int fileAgeInDays;
阅读全文 »