类继承命名

发布于 2024-08-04 00:08:41 字数 390 浏览 4 评论 0原文

我想继承 DevExpress ComboBoxEdit 控件,并且想知道将我的类命名为与 DevExpress 类相同的名称是否是不好的做法。

这是派生类声明:

using System;
using System.Collections.Generic;
using System.Text;

namespace MyApplication.Components
{
    public class ComboBoxEdit : DevExpress.XtraEditors.ComboBoxEdit
    {
    }
}

我应该将 MyApplication.Components.ComboBoxEdit 重命名为 MyComboBoxEdit 之类的其他名称吗?

I want to inherit the DevExpress ComboBoxEdit control, and am wondering if naming my class the same as the DevExpress class is bad practice.

Here's the derived class declaration:

using System;
using System.Collections.Generic;
using System.Text;

namespace MyApplication.Components
{
    public class ComboBoxEdit : DevExpress.XtraEditors.ComboBoxEdit
    {
    }
}

Should I rename MyApplication.Components.ComboBoxEdit to something else like MyComboBoxEdit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

温折酒 2024-08-11 00:08:41

您创建自己的 ComboBoxEdit 一定是有原因的。我会在班级的名称中使用这个原因。

There's must be a reason why you're creating your own ComboBoxEdit. I would use that reason in the name of the class.

笨死的猪 2024-08-11 00:08:41

只有当你想让维护人员像一千个太阳一样讨厌你时,这才是个好主意。

It's a good idea only if you want the maintenance dude to hate you with an intensity of a thousand suns.

哭了丶谁疼 2024-08-11 00:08:41

使用常识。

1) 如果您的组合框和 DevExpress 组合框在整个应用程序中都使用,则将其命名为不同的名称(但仍然揭示其身份)。

2)如果您有一个明确定义的约定,您将从某个名称空间继承所有组件并仅使用您自己的组件,那么我认为这样做没有问题。

Use common sense.

1) If both your and the DevExpress combo boxes are used throughout the application name it something different (but still something that reveals its identity).

2) If you have a well defined convention that you will inherit all components from a certain namespace and use only your own then I see no problem with doing this.

青萝楚歌 2024-08-11 00:08:41

好吧,这样做是合法的,但我建议不要这样做,因为它只会引起混乱......为什么不将其命名为“MyComboBoxEdit”或“SuperComboBoxEdit”或任何您喜欢的名称?

Well, it's legal to do it, but I would advise against it because it would only cause confusion... Why not name it "MyComboBoxEdit" or "SuperComboBoxEdit" or anything you like ?

请别遗忘我 2024-08-11 00:08:41

从技术上讲,您的班级已经有了不同的名称。您的类名为“MyApplication.Components.ComboBoxEdit”,DevExpress 类名为“DevExpress.XtraEditors.ComboBoxEdit”。

也就是说,您的类可能与 DevExpress 类具有不同的行为。因此,您应该为新类指定一个更具描述性的名称。

Technically, your class has a different name already. Your class is named "MyApplication.Components.ComboBoxEdit" and the DevExpress class is named "DevExpress.XtraEditors.ComboBoxEdit".

That said, your class likely has different behavior to the DevExpress class. For this reason you should probably give your new class a more descriptive name.

挽心 2024-08-11 00:08:41

如果您(以及您的同事/其他将在该应用程序上工作的人)不会感到困惑,那么使用相同的名称是完全合法的 - 毕竟,这就是名称空间存在的原因。

否则,您可能想根据扩展基类的原因来命名您的类,例如 ComboBoxEditThatAlsoDoesThisAndThat,而不是使用通用的 My 前缀...

If it's not confusing for you (and your coworkers / other people that will work on the application) then it's perfectly legitimate to use the same name - that's why namespaces exist, after all.
Otherwise you might want to name your class after the reason you're extending the base one, e.g. ComboBoxEditThatAlsoDoesThisAndThat, rather than using the generic My prefix...

时光无声 2024-08-11 00:08:41

我也建议不要出现命名冲突。关于名称,如果您有理由创建继承控件,那么您应该能够给出一个有用的名称。

My 前缀有严重的限制,对于阅读代码的新手来说没有什么价值。当您需要新的 MyComboBox2 时,您还可能面临遇到 MyComboBox2 的风险。

I too would advise against a naming collision. With respect to the name, if you have a reason to create an inherited control, then you should be able to give a useful name.

The My prefix is severely limiting and has little value to newcomers reading the code. You also risk running into MyComboBox2 when you need a new one.

真心难拥有 2024-08-11 00:08:41

它没有什么非法的,但如果你最终在不同的文件中使用这样的 using 语句,你就会遇到问题。

using DevExpress.XtraEditors;

然后你最终将类名隐藏在智能感知中(因为两个类具有相同的名称);所以你必须明确指定你正在使用哪个类。

我假设...我从未使用过 Dev Express。我不知道 XtraEditors 是否是一个命名空间。

There is nothing illegal about it, but if you end up with a using statement like this in a different file, you'll run into problems.

using DevExpress.XtraEditors;

Then you end up burying the class name in intellisense (since two classes have the same name); so then you'll have to explicitly specify which class you are using.

I'm assuming... I've never used Dev Express. I don't know if XtraEditors is a namespace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文