Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using interfaces is just generally good practice in Java. Some languages have multiple inheritance, others have duck typing, Java has interfaces. It's a key feature of the language, it lets me use </p> <ol> <li>different aspects of a class in different contexts and </li> <li>different implementations of the same contract without changing client code.</li> </ol> <p>So interfaces are a concept you should embrace in general, and then you would reap the benefits in situations like this where you could substitute your services by mock objects. </p> <p>One of the most important books about Java best practices is <a href="http://java.sun.com/docs/books/effective" rel="nofollow">Effective Java by Joshua Bloch</a>. I would highly suggest you to read it. In this context the most important part is <strong>Item 52: Refer to objects by their interfaces</strong>. Quote:</p> <blockquote> <p>More generally, you should favor the use of interfaces rather than classes to refer to objects. <strong>If appropriate interface types exist, then parameters, return values, variables, and fields should all be declared using interface types.</strong> The only time you really need to refer to an object’s class is when you’re creating it with a constructor.</p> </blockquote> <p>And if you take things even further (e.g. when using dependency injection), you aren't even calling the constructor.</p> <p>One of the key problems of switching languages is that you have to switch the way of thinking too. You can't program language x effectively while thinking in language y. You can't program C effectively without using pointers, Ruby not without duck typing and Java not without Interfaces.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload