Note that there are some explanatory texts on larger screens.

plurals
  1. POJava vs. OO Design
    text
    copied!<p>I'm working on an inherited system which has some design issues which "OO Buzzwords" frown upon, and some I personally dislike.</p> <p>It's a stock and sales handling program for a comic book store.</p> <p>I have an <code>Article</code> class, which can be any item (Magic cards, toys), and a <code>Publication</code> class that inherits from Article, which represents books and magazines. A <code>Publication</code> has Authors and optionally issue number, while an Article doesn't.</p> <p>There's an Article Editor, which is a GUI to create and modify articles. Since there's the possibility to load a Publication with an error, and not add a volume number, the interface to work with an article is:</p> <pre><code>Article a = EntityManager.loadArticle(articleId); ArticleEditor editor = new ArticleEditor(a); a = e.getValue(); </code></pre> <p>to allow a to be changed into a Publication, should the need arise.</p> <p>One of my peeves is that this could be handled more gracefully if it used references, or ar least so it appears to me. My current version uses wraps the last 2 lines' pattern in a static version, but it still looks ugly because it looks too state-dependent.</p> <hr> <p>The second issue comes with Java's (and most "enterprise" languages') lack of multiple dispatch: the EntityManager has a <code>save()</code> method, overloaded for both <code>Article</code>s and <code>Publication</code>s. This causes a huge issue if I say, for example:</p> <pre><code>Article a = EntityManager.loadArticle(articleId); ArticleEditor editor = new ArticleEditor(a); a = e.getValue(); EntityManager.save(a); </code></pre> <p>This is currently "solved" by having the ArticleEditor save changes (which seems wrong).</p> <p>I'm sure there must be some way to adjust the design to eliminate these issues. (I don't mind a whole re-write, if need be.)</p> <p><strong>How can I adjust the design to eliminate these issues?</strong></p> <p>Edit: Publication has Authors, too, not only Numbers.</p>
 

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