0

I'm struggling with a naming issue. What name would you give to an interface that have just one method with this signature:

public interface ?
{
    boolean isAvailable();
}

Many classes in my application can implement this interface.

Marcos
  • 1,237
  • 1
  • 15
  • 31
  • 2
    Just because something can be available or not means nothing. There is a design problem, if you try to write an interface that you can't give a name. You need to know what this interface means, what will you do with something, that you only know is available? You can do nothing with that, because it has no meaning. – Krzysztof Cichocki May 22 '15 at 12:36
  • 1
    Even though the interface is really very general and abstract, I still think that it means something and is useful in some way. Look at the interface `Closeable` in Java. – Marcos May 22 '15 at 12:41
  • No, it have no meaning. Ok, let's say you implement the available method in all your objects in your code. What can you do with the information that something is available? What interaction could you take with this object, if you don't know anything about it, just that it is available? – Krzysztof Cichocki May 22 '15 at 12:44
  • I can, for example, not show the object in a JSF web page if it is not available. This interface will be used in a specif domain model I'm developing and it means exactly this. – Marcos May 22 '15 at 12:48
  • You shouldn't have one interface for all objects that can have available method. You should name this interface at least as JspDataAvailabilityStatus, or even better name what type of objects is available – Krzysztof Cichocki May 22 '15 at 12:51
  • Just because something has a hole, it don't mean you can have sex with that. Do you catch the idea, that to much generalization is bad? – Krzysztof Cichocki May 22 '15 at 12:52
  • I still think that I should, because of this I can treat object uniformily without knowing how availability is implemented in each object. For one object availability can mean if the object is active, for example, for others it can mean a different thing. I can even treat leaf and composite objects uniformily. I just have to pass an object of type `Available` to some method and the method doesn't care how availability is implemented. – Marcos May 22 '15 at 12:55
  • Your interface is to general, it does not describe any group of objects, because all Objects can be available or not. When some programmer came after you to develop this code, you will probably need to leave your country to save your life :P just kidding... but you can make someone mad with this style of generalizing everything, belive me. It is bad just because other programmer would not know what it means, that everything could be available or not, do You catch that? – Krzysztof Cichocki May 22 '15 at 13:00
  • It looks like you're tying frontend logic into backend objects, which is a bad idea. Any way you look at it, this smells and there's no way I can be convinced this is a good idea. – Davio May 22 '15 at 13:02
  • Yes, I understand this. But the objects that I'm developing in my domain model really have the notion of availability. I'm not saying that this interface will apply to everything. For example, does a class named `Name` that have firstname and surname should implemente an interface like this? I don't think so. So I do think that not all objects are candidate to implement this interface. The interface is not so general like this, but it suits the entity classes that I'm developing because they have atributes like 'active' and 'period' (a date range) that can be abstracted in `isAvailable()`. – Marcos May 22 '15 at 13:06
  • 1
    @Davio. if you see my last comment you'll see that I'm not tying font and backend logic in objects. The concept of availability in my domain model is a concept that the frontent has to honor, not matther which frontend. It is intrinsic in the model. – Marcos May 22 '15 at 13:11

3 Answers3

3

Not that it really matters, you can rename it any time afterwards, and with current IDEs, it is really easy to type any name using autocomplete...

That said, if you want it short, use Available, if you want it more self-explanatory, use CanBeAvailable.

P.Péter
  • 1,527
  • 16
  • 39
2

Given that the word "available" already ends with "-able", I think it's okay to break with the Java interface naming convention and call it Availability. Another approach, suggested in Programmers, is to use the prefix "Can-", in which case you can call your interface CanBeAvailable.

Community
  • 1
  • 1
Joey deVilla
  • 8,403
  • 2
  • 29
  • 15
2

The below are the standards defined for Naming conventions.

Class - Always be a Noun

Interface - Always be an Adjective

Method - should be a verb

So, think of some adjective which describes the purpose of your interface.

Bhargav Kumar R
  • 2,190
  • 3
  • 22
  • 38