Class inheritance naming

2019-07-07 05:52发布

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?

8条回答
何必那么认真
2楼-- · 2019-07-07 06:21

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

查看更多
Emotional °昔
3楼-- · 2019-07-07 06:25

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

查看更多
够拽才男人
4楼-- · 2019-07-07 06:28

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...

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-07-07 06:28

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.

查看更多
▲ chillily
6楼-- · 2019-07-07 06:30

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.

查看更多
冷血范
7楼-- · 2019-07-07 06:31

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.

查看更多
登录 后发表回答