英文:
Use a Collection inside my custom collection?
问题
这是翻译好的内容:
使用已经实现的集合(比如 ArrayList)来实现自定义集合,是否正确?或者可能会有问题?
类似这样:
public class customCollection<E> implements Collection<E> {
List<E> objects = new ArrayList<E>();
}
英文:
Is it correct to use an already implemented Collection (like a ArrayList) to implement my custom collection? Or could be there any problem?
Something like this:
public class customCollection<E> implements Collection <E> {
List<E> objects = new ArrayList<E>();
}
答案1
得分: 2
这完全没问题。
我有一些专门的数据类(还具有一些业务逻辑),它们实现了一种标准类型,并在内部为其他原因使用了各种对象。
要注意不要产生难以维护的代码。为此,你可以使用诸如SonarQube之类的工具。检查一下,当你依赖(许多)类时,你使用了多少 - 换句话说,你的类对其他接口、类、继承方法有多依赖?参考,例如http://tutorials.jenkov.com/ood/understanding-dependencies.html
英文:
That is absolutely OK.
I have specialised data classes (that also have some business logic) that implement one standard type and have internally various objects for other reasons.
Take care to not produce unmaintainable code. For this, you could use tools such as SonarQube. Check, when you rely on (many) classes, how much do you use - in other words, how dependent is your class froom other interfaces, classes, inherited methods? See, for example http://tutorials.jenkov.com/ood/understanding-dependencies.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论