Note that there are some explanatory texts on larger screens.

plurals
  1. PODesign pattern for default implementation with empty methods
    primarykey
    data
    text
    <p>Is there a specific <strong>design pattern</strong> that describes the scenario where a non-abstract default implementation is provided that implements all or some of the methods on the interface with empty, NO-OP implementations. This being done with the intent of alleviating subclasses with the burden of implementing methods that they themselves may not need/use:</p> <pre><code>public interface MyInterface { public void doThis(); public void doThat(); public void done(); } public class MyClass implements MyInterface { public void doThis() { // NO-OP } public void doThat() { // NO-OP } public void done() { // Some standard implementation } } public class MuSubClass extends MyClass { public void doThat() { // Subclass only cares about doThat() } } </code></pre> <p>I have seen this pattern used a number of times including <a href="https://docs.oracle.com/javase/8/docs/api/org/xml/sax/helpers/DefaultHandler.html" rel="noreferrer">Java's DefaultHandler in the SAX framework</a>, and <a href="https://docs.oracle.com/javase/8/docs/api/java/awt/event/MouseAdapter.html" rel="noreferrer">MouseAdapter</a>. In somes cases such classes are named as Adaptors, but I was under the impression that the adapter pattern translates between two different interfaces. </p> <p>Given that in these instances there is only one declared interface that is being translated to an undefined subset of that interface - I am not clear on how this is in the spirit of the adapter pattern.</p> <p>Furthermore, I don't quite see how this adheres to the <a href="http://en.wikipedia.org/wiki/Null_Object_pattern" rel="noreferrer">NullObject pattern</a> either, given that some methods could have an implementation, and the NullObject is traditionally a singleton.</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.
 

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