Note that there are some explanatory texts on larger screens.

plurals
  1. POOO design of Books and Tags
    primarykey
    data
    text
    <p>I'm doing a basic exercise of object-oriented design for a simple use case: <em>A Book can be tagged with many Tags.</em></p> <p>I have many solutions, and I would like your input on which is better in term of OOD principles and maintanability.</p> <p><strong>Option 1</strong></p> <pre><code>public class Book { private String title; //... other attributes private List&lt;Tag&gt; tags; } </code></pre> <p>The thing that bothers me is that we mixed core attributes of a Book with additional categorization or search data. I may have in the future a requirement where certain Books can't be tagged. In the future, the Book class can become bloated when I add more responsabilities: category, list of users that read it, ratings...</p> <p><strong>Option 2</strong></p> <pre><code>public class TaggedBook extends Book { private Book book; private List&lt;Tag&gt; tags; } </code></pre> <p>I think this is similar to the Decorator pattern, but I don't see it fit here because I'm not extending behavior.</p> <p><strong>Option 3</strong></p> <p>Decouple Books and Tags comnpletely, and use a service to retrieve Tags from a book (given each Book has a unique identifier)</p> <pre><code>List&lt;Tag&gt; TagService.getTags(Book book) </code></pre> <p>However, I don't find this solution very elegant (is it?), and I may have to send two queries: one to retrieve the book, the other for the tags.</p> <p>I am planning on applying the best options to other requirements: A Book has a rating, a Book can be categorized...</p> <p>I'm also planning on using a DMS to store Books and Tags objects. Since it's not a relations database, its schema will likely correspond to the class design.</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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