Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like you can use the <a href="http://en.wikipedia.org/wiki/Decorator_pattern" rel="nofollow noreferrer">decorator pattern</a> and write e.g. a <code>ThrottledEmail</code>. It simply decorates another instance of <code>Email</code> (it can be <em>ANY</em> <code>Email</code> subclass) and it can <code>@Override</code> the <code>send</code> method to enforce some throttling. All other methods are simply delegated to the underlying <code>Email</code> instance.</p> <p>This is similar to how a <a href="http://java.sun.com/javase/6/docs/api/java/io/BufferedReader.html" rel="nofollow noreferrer"><code>java.io.BufferedReader</code></a> works, for example. It can decorate any <code>Reader</code> to give it a buffering feature. Other examples include <a href="http://java.sun.com/javase/6/docs/api/java/util/Collections.html" rel="nofollow noreferrer"><code>java.util.Collections</code></a> that provides utility methods such as <a href="http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#synchronizedCollection%28java.util.Collection%29" rel="nofollow noreferrer"><code>Collection&lt;T&gt; synchronizedCollection(Collection&lt;T&gt;)</code></a> which wraps <em>ANY</em> <code>Collection&lt;T&gt;</code> and decorates it with synchronization features.</p> <p>Unless the base class is clearly documented to facilitate subclasses to <code>@Override</code> certain methods, you should generally favor composition (<em>has-a</em>) over inheritance (<em>is-a</em>) relationship.</p> <h3>See also</h3> <ul> <li><em>Effective Java 2nd Edition, Item 16: Favor composition over inheritance</em></li> <li><em>Effective Java 2nd Edition, Item 17: Design and document for inheritance, or else prohibit it</em></li> </ul> <h3>Related questions</h3> <ul> <li><a href="https://stackoverflow.com/questions/3477962/when-do-we-need-decorator-pattern">when do we need Decorator Pattern?</a></li> <li><a href="https://stackoverflow.com/questions/49002/prefer-composition-over-inheritance">Prefer composition over inheritance?</a></li> <li><a href="https://stackoverflow.com/questions/1673841/examples-of-gof-design-patterns">Examples of GoF Design Patterns</a></li> <li><a href="https://stackoverflow.com/questions/3502066/guava-forwardinglist-usage-example">Guava <code>ForwardingList</code> usage example</a></li> </ul>
    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