Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a good name for interface with inUse() method [closed]

Tags:

java

c#

How would you name an interface which provides 1 method inUse()?

like image 726
Thomas Avatar asked Jun 24 '11 09:06

Thomas


2 Answers

I would actually reconsider the name 'inUse()' in the first place; A boolean value obviously has only two possible values, but you're actually adding the ability to get a state. I'd consider declaring an enum

public enum UsageState
{
    Idle,
    InUse
}

and name your interface IHasUsageState. This gives you the flexibility of adding things like Starting, Finishing, WaitingToBeUsed or other options depending on precisely what is is you're doing, for example if you have threading issues to deal with in the future.

Also, you eliminate the need for negative checks like if (!obj.InUse()) { } in favor of the more readable and intuitive if (obj.Usage == UsageState.Idle) { }, not to mention you may decide in the future that you might want it to specify WHY it's idle.

like image 158
Flynn1179 Avatar answered Nov 15 '22 02:11

Flynn1179


IUsageIndicator if you want to show that your object is currently in use or not.

IUsable if you want to show that your object can be used or not.

like image 32
Dummy01 Avatar answered Nov 15 '22 02:11

Dummy01