@FunctionalInterface
只能标记类型(类、接口、注解、枚举)。
命名类型时应使用名词,而对于方法,则需要使用动词。
Classes
Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).
class Raster;
class ImageSprite;
Methods
Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
run();
runFast();
getBackground();
Naming Conventions, Oracle
这是一个关于如何定义函数式接口的示例:
以下是我定义函数式接口的示例。
@FunctionalInterface
interface Decorator {
void decorate();
}
在代码中,它看起来可读性很高。
Decorator decorator = () -> {}
decorator.decorate()
我对“装饰器 vs 装饰品”的看法:
"装饰品"
更多地描述了过程/结果,而"装饰器"
是启动该过程/获得该结果的机制/工具/手段。
如果我在代码中看到Decoration
类,我会想到一堆装饰品(如装饰品、油漆、壁纸),而不是真正的装饰者。
如果我看到Decorator
或Painter
,我会期望像decorate()
或paint()
这样的方法,因为这是他们可以/应该做的。
比较suppliance/supplier -> get()
和consumption/consumer -> accept(t)
。