It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center




9年前关闭。




您如何命名一个提供inUse()方法的接口?

最佳答案

实际上,我会首先重新考虑名称“inUse()”。布尔值显然只有两个可能的值,但实际上是在添加获取状态的功能。我会考虑声明一个枚举

public enum UsageState
{
    Idle,
    InUse
}

并命名您的接口IHasUsageState。这使您可以灵活地根据正在执行的操作添加StartingFinishingWaitingToBeUsed或其他选项,例如,如果将来有线程问题要处理。

此外,您无需像if (!obj.InUse()) { }这样的否定检查,而是希望使用更具可读性和直观性的if (obj.Usage == UsageState.Idle) { },更不用说您将来可能会决定是否希望它指定空闲状态。

07-24 18:46