Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Programming to interfaces provides several benefits:</p> <ol> <li><p>Required for GoF type patterns, such as the visitor pattern</p></li> <li><p>Allows for alternate implementations. For example, multiple data access object implementations may exist for a single interface that abstracts the database engine in use (AccountDaoMySQL and AccountDaoOracle may both implement AccountDao)</p></li> <li><p>A Class may implement multiple interfaces. Java does not allow multiple inheritance of concrete classes.</p></li> <li><p>Abstracts implementation details. Interfaces may include only public API methods, hiding implementation details. Benefits include a cleanly documented public API and well documented contracts.</p></li> <li><p>Used heavily by modern dependency injection frameworks, such as <a href="http://www.springframework.org/" rel="nofollow noreferrer">http://www.springframework.org/</a>.</p></li> <li><p>In Java, interfaces can be used to create dynamic proxies - <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Proxy.html" rel="nofollow noreferrer">http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Proxy.html</a>. This can be used very effectively with frameworks such as Spring to perform Aspect Oriented Programming. Aspects can add very useful functionality to Classes without directly adding java code to those classes. Examples of this functionality include logging, auditing, performance monitoring, transaction demarcation, etc. <a href="http://static.springframework.org/spring/docs/2.5.x/reference/aop.html" rel="nofollow noreferrer">http://static.springframework.org/spring/docs/2.5.x/reference/aop.html</a>.</p></li> <li><p>Mock implementations, unit testing - When dependent classes are implementations of interfaces, mock classes can be written that also implement those interfaces. The mock classes can be used to facilitate unit testing.</p></li> </ol>
 

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