gpt4 book ai didi

java - 接口(interface)作为标签在 Java OO 中是一种不好的做法吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:31:32 25 4
gpt4 key购买 nike

我在解析某些xml文件的过程中,遇到一种情况,我必须使用接口(interface)作为标签来标识某些标签属于某个类别,例如我创建了一个Tag接口(interface)来标识这些类用于表示xml标签,ContainableTag指出某些标签可以是某些标签的子标签之一。

然后我无意中进入了这个页面:http://xahlee.org/java-a-day/interface.html (请查找“作为标签的界面” session 。)它说:

The gist of the problem is that it isa piece of mathematical irrelevance inthe language. As a labeling mechanismin a language, for the possiblebenefit from the software engineeringperspective, then it should not bedesigned as part of the ClassInterface, since the concept oflabeling, and concept of programinginterface, are semantically disparate.

那么界面作为标签一定是一种不好的做法吗?作为一名java程序员,我们还有其他的选择吗?

最佳答案

作为标记的接口(interface)在很大程度上已被 Java 5 或更高版本中的注释机制所取代。它们允许您添加任意元数据。如果您的接口(interface)是空的并且仅用作类标记,那么您应该改用注释。

关于java - 接口(interface)作为标签在 Java OO 中是一种不好的做法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1436674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com