【发布时间】:2015-08-17 02:04:51
【问题描述】:
Scala 枚举类型的命名约定是什么?例如,在下面的代码中:
object EventType extends Enumeration {
type EventType = Value
val Registered = Value("Registered")
val Started = Value("Started")
}
/**
* The event that fires under specific life cycle
*
* @param eventType the [[EventType.EventType]]
*/
case class Event(eventType: EventType.EventType)
上面的代码遵循Scala doc中描述的相同风格。这里的问题是,与 Java 或 C# 等其他语言中的枚举定义相比,您可以看到“EventType.EventType”的名称非常多余,而且非常奇怪。
所以我想知道是否有任何推荐的命名风格来提高可读性?
提前致谢。
【问题讨论】:
-
您可能已经意识到这一点,但许多 scala 程序员避免使用 Enumeration 类,而是使用密封的基类型和 case 对象作为可能的值。如果您有兴趣,可以在此问题的答案中阅读更多内容:stackoverflow.com/questions/1321745/…
-
非常感谢您的评论。我从这个帖子中学到了很多