臭名字类名? [英] Smelly class names?

查看:161
本文介绍了臭名字类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据您的经验,在类或函数名称中有些臭关键字可能是不良面向对象设计的警告标志?

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, and AddressParser. Avoid words like Manager, Processor, Data, or Info 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆