臭名字类名? [英] Smelly class names?
问题描述
根据您的经验,在类或函数名称中有些臭关键字可能是不良面向对象设计的警告标志?
In your experience, what are some "smelly" keywords in class or function names that might be warning signs of bad object-oriented design?
包含单词 Manager
或 Base
的类通常是可疑的。例如, FooManger
通常表示封装不良或难以重用的单例设计。
I've found that classes containing the word Manager
or Base
are often suspect. For example, a FooManger
often indicates poor encapsulation or a singleton design that is difficult to reuse.
A FooBase
类通常是一个抽象的基类,从来不希望在调用者代码中直接引用。它只用于分享一些代码实现,而没有真正的 IS-A 关系。并且 Base
类名暴露了内部实现细节,并不反映域模型中的真实世界对象。
A FooBase
class is typically an abstract base class that is never expected to be directly referenced in caller code. It's only used to share some code implementation without a true IS-A relationship. And the Base
class name exposes internal implementation details and does not reflect a "real world" object in a Domain Model.
包含字和
或或
例如 DoThisAndThat()
或 DoThisOrThat()
)是臭的。这个功能可能缺乏凝聚力,试图做太多。
Functions that include the word And
or Or
(e.g. DoThisAndThat()
or DoThisOrThat()
) are smelly. The function is probably lack cohesion and is trying to do too much. And the name exposes internal implementation details.
推荐答案
我发现这是有帮助的:
类和对象应该有名称或名词短语名称,例如
Customer
,WikiPage
,
帐户
和AddressParser
,避免像Manager
,处理器
,数据
或Info
"Classes and objects should have noun or noun phrase names like
Customer
,WikiPage
,Account
, andAddressParser
. Avoid words likeManager
,Processor
,Data
, orInfo
in the name of a class. A class name should not be a verb."
(从 Clean Code by Robert Martin,p25)
(From Clean Code by Robert Martin, p25)
这篇关于臭名字类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!