29 Mai 2008

Only two reasons for declaring an interface

I had several discussions about when it makes sense to declare an interface in Java.

I only found two possible reasons!
  1. If you could have more than one implementation of this interface (I think this is the original intention for interfaces)

  2. If you want to use proxies. (i.e. remoting or dynamic proxies)
In any other cases you should think twice if there is really a need for an interface!
This sounds very simple in a way, but I think this is an important finding.

If you know any other important reason - please let me know!

Keine Kommentare: