Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think it would be better to mix pattern for a better solution. Remember a particular pattern only solves one particular problem.</p> <p>My suggestion is to isolate different interfaces and join them accordingly. The base class should have the ability to query for supported interfaces, so that it can call the appropriate interface functions.</p> <p>First interface is the query supported interface:</p> <pre><code>public interface QueryInterface { public boolean isTaggable(); public boolean isRatable(); } </code></pre> <p>...next comes particular interfaces.</p> <p>Suppose the first particular interface is taggable:</p> <pre><code>public interface Taggable { public Vector&lt;Tag&gt; getTags(); public boolean addTag(Tag newTag); } </code></pre> <p>...and the second one is rateable...</p> <pre><code>public interface Rateable { public Rating getRating(); public void setRating(Rating newRating); } </code></pre> <p>The plain old base class itself: :)</p> <pre><code>public class Book implements QueryInterface { private String title; public boolean isTaggable() { return false; } public boolean isRateable() { return false; } } </code></pre> <p>Now the special derived class which complies to the taggable interface:</p> <pre><code>public class TaggedBook extends Book implements Taggable { private Vector&lt;Tag&gt; tags; public Vector&lt;Tag&gt; getTags() { return tags; } @override public boolean isTaggable() { return true; } public boolean addTag(Tag newTag) { return tags.insert(newTag); } } </code></pre> <p>...and the different book which is rateable only:</p> <pre><code>public class RatedBook extends Book implements Rateable { private Rating rating; public Rating getRating() { return rating; } public void setRating(Rating newRating) { this.rating = newRating; } @override public boolean isRateable() { return true; } } </code></pre> <p>Hope this helps. :) </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. 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