使用“碱基”在类名称 [英] Using "Base" in a Class Name

查看:130
本文介绍了使用“碱基”在类名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在作为继承树底部的类名中使用单词'Base'是否可以接受?



我一直觉得这有点



例如,如果我将MyClassA和MyClassB中的某些元素重构为一个共同的基类,我会试图创建一个MyBaseClass从这两个继承。



但是如果我需要重构MyBaseClass会发生什么? MyBaseBaseClass?



我知道Rocky Lhotka不介意他的CSLA框架,但我总是对编程中的定义不安。



想法?



让我澄清为什么 p>

我有两个命名空间 - MySpecificNamespace和MyCommonNamespace。 MyNamespace使用MyCommonNamespace,正如你所期望的。



现在,我喜欢尽可能地使用命名空间来描述问题的上下文,并避免添加上下文类名。因此,例如,考虑我在MyNamespace中有一个类,它来自MyCommonNamespace中的一个。



选项A



I 可以调用此 $

  MySpecificClass:MyClass 
{
}

但是我添加了'Specific'(上下文)它已经在MySpecificNamespace中。



选项B

  MyClass:MyCommonNamespace.MyClass 
{
}

你可以看到我们在这里会感到困惑吗? >

选项C



我认为是鱼腥的:

  MyClass:MyBaseClass 
{
}


解决方案

我倾向于添加一个Base后缀到基类的名称,只要它存在从技术角度(共享一些代码),并不真正构成任何可用的类上它自己的(所有这些类都是抽象的)。这些是非常罕见的情况,但应该避免只是Helper类。


Is it acceptable to use the word 'Base' in a class name which is a the bottom of the inheritance tree?

I have always found this a bit of a cop-out, just wondering if anyone agrees with me.

For example, if I am refactoring certain elements from MyClassA and MyClassB into a common base class, I'd be tempted to create a MyBaseClass from which the two inherit.

But what happens if I ever need to refactor MyBaseClass? MyBaseBaseClass? Now that's just silly.

I know that Rocky Lhotka doesn't mind with his CSLA framework, but I'm always uneasy about 'definites' in programming.

Thoughts?

Let me clarify why I'm even worrying about this.

I have two namespaces - MySpecificNamespace and MyCommonNamespace. MyNamespace uses MyCommonNamespace, as you might expect.

Now, I like to make maximum use of Namespaces wherever possible to describe the context of the problem, and avoid adding the context to the class name. So, for example, consider that I have a class in MyNamespace which descends from one in MyCommonNamespace.

Option A

I could call this

MySpecificClass: MyClass
{
}

But then I'm adding 'Specific' (the context) to the name - which is redundant as it's already in MySpecificNamespace.

Option B

MyClass: MyCommonNamespace.MyClass
{
}

You can see how we could get confused here, right?

Option C

The one I think is fishy:

MyClass: MyBaseClass
{
}

解决方案

I tend to add a Base suffix to the name of the base class only if it exists from technical perspective (to share some code), and doesn't really constitute any usable class on its own (so all of these classes are abstract). These are quite rare cases though, and should be avoided just as Helper classes.

这篇关于使用“碱基”在类名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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