不好的做法是在不同的程序包中有两个同名的类? [英] Bad practice to have two classes of the same name in different packages?

查看:97
本文介绍了不好的做法是在不同的程序包中有两个同名的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经拆分了应用程序,以便程序包A处理来自一个外部源的数据,而程序包B处理来自另一个外部数据源的数据.在这两种情况下,我们都需要创建一个域对象并有一个"Transformer"来实现.

We have split our application so that package A handles data from one external source and package B from another. In both cases we need to create a domain object and have a "Transformer" to do this.

所以我有com.foo.bar.a.ThingTransformercom.foo.bar.b.ThingTransformer

我怀疑这是不好的做法,但想看看SO的好人怎么想.

I suspect that this is poor practice, but want to see what the good people of SO think.

推荐答案

我不会说这总是一个坏习惯,但这有点像

I wouldn't go as far as saying that it's always a bad practice, but it's somewhat of a code smell.

如果这两个类都做不同的事情,那么为什么它们没有不同的名称?

If both classes do different things, then why don't they have different names?

如果这两个类都做同一件事,那么为什么会有两个类?

if both classes do the same thing, then why are there two classes?

从实际的角度来看,如果这两个类必须在同一个类中引用,可能会变得非常非常:您必须使用

From a practical standpoint it can become very annoying if those two classes ever need to be referenced in the same class: you'll have to use the FQN for one of those (it would probably be best to use it for both in this case, for clarity). If those two classes are in sufficiently distinct parts of the code that they won't be referenced from the same code, then the practical problem is not so bad.

这篇关于不好的做法是在不同的程序包中有两个同名的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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