-1

Is there any convention on how to name your interfaces? I do not mean the implementations, just the interface!

What about the suffix '-able'? Like Runnable, Closeable, Serializable? When to use this?

Ercksen
  • 668
  • 9
  • 23
  • This question has been already answered here: http://stackoverflow.com/questions/2814805/java-interfaces-implementation-naming-convention and http://stackoverflow.com/questions/17275344/java-interface-naming-conventions – Maciej Miklas Mar 23 '14 at 13:39

1 Answers1

0

A common design pattern in Java is to give your interface a very basic name, such as Graph, and then give the implementation the suffix Impl, such as GraphImpl.

Ghostkeeper
  • 2,830
  • 1
  • 15
  • 27
  • Too generic IMHO. What if you have several implementations ? – giorashc Mar 23 '14 at 13:40
  • If I want to create an interface with methods for drawing images on a JPanel (`getX()`, `getY()`, `getImage()`...), would it be understandable to call it `Drawable`? If not so, why not? – Ercksen Mar 23 '14 at 13:41
  • 2
    Giving clear names is in my opinion more important than to follow this convention. With several implementations I'd give them names `AdjacencyListGraph` and `AdjacencyMatrixGraph` for instance, and `Drawable` is a very good name for drawable stuff. – Ghostkeeper Mar 23 '14 at 13:42
  • 1
    It is a common, but horrible Convention. I prefer the convention used in the Collection library. The interface says what it does, the class name says how it does it. E.g. List vs. ArrayList – Sean Patrick Floyd Mar 23 '14 at 14:00
  • In my opinion, using "Impl" as suffix for the implementation is really a horrible idea as @SeanPatrickFloyd said. Because, when you add "Impl" you do not have a clear purpose why you are using this class. When the purpose is clear, the naming will be available easier. – Muneer Sep 06 '20 at 08:08