Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I consider your approach to be the best overall. This comes after having tested with a number of different approaches myself.</p> <p>I see a number of huge benefits in your current approach, namely:</p> <ol> <li>Easily <strong>readable and understandable</strong> by anyone (in my experience, medium-level programmers often underestimate this and usually prefer going with fancy-patterns which, in the end are not readable at all for the vast majority of programmers who do not know that specific pattern)</li> <li>All the <strong>information is in one single place</strong>. As Andreas_D pointed out, hunting around files or classes is not a good option for someone that needs to fix a bug while you are on holiday!</li> <li>Easily <strong>maintainable</strong>: I could "F3" (if you are Eclipse-ing) on the method and add a new content type in seconds without any worries of introducing bugs!</li> </ol> <p>I can suggest a few things anyway:</p> <ol> <li>This method is very general purpose: Why should it be private?! This is a <strong>public method</strong> of some utility/helper class! Moreover it should be a <strong>static method</strong>!! You don't need anything from the Object itself to perform your job!</li> <li>You could use <strong>indenting</strong> to make things prettier and compact. I know that indenting is some kind of religion for the most of us, but I think it should not be a strict rule; it should be properly used to make our code more <strong>readable and compact</strong>. If this would be a config file you would probably have something like:</li> </ol> <blockquote> <pre><code>pdf=application/pdf doc=application/msword </code></pre> </blockquote> <p>You could have a very similar result with:</p> <pre><code> public static String getMimeType(String fileName){ if(fileName == null) return ""; if(fileName.endsWith(".pdf")) return "application/pdf"; if(fileName.endsWith(".doc")) return "application/msword"; if(fileName.endsWith(".xls")) return "application/vnd.ms-excel"; return "txt/plain"; } </code></pre> <p>This is also what a lot of the Map based implementations look like.</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