【发布时间】:2023-03-14 20:31:01
【问题描述】:
假设我有几个类在内部共享一些行为,例如
def workspace = Plugin.get.reallyGet.getWorkspace
排除它的最佳方法是什么?我看到了两种可以在 using 代码中等效使用的可能性。
trait WorkspaceProvider {
def workspace = Plugin.get.reallyGet.getWorkspace
}
并混合它或
object WorkspaceProvider {
def workspace = Plugin.get.reallyGet.getWorkspace
}
并导入它。你更喜欢什么?为什么?
【问题讨论】:
标签: scala coding-style refactoring