Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Disclaimer:</strong> <em>The following are not hard and fast rules. These are just my opinions and personal preferences. I personally find that it makes my code easier to read and easier to maintain.</em></p> <p>First a question. Where did you come across this advice? Did they provide any rationale?</p> <p>In my experience, I've normally used private nested enums to enhance readability and maintainability of my code. This especially comes into play when you're performing an integration with another system and you have to send in specific strings or numbers. I find that using an enum makes things easier to read and maintain. In this specific case, the information conveyed by the enum is limited in scope to the class (i.e., it makes no sense outside the class and no one else should need it).</p> <p>I can't think of a definitive reason that says why public inner enums are a bad practice. But here are reasons why I don't (normally) use them:</p> <ul> <li>If the enum is public, it essentially means that it conveys information in a larger scope (i.e., makes sense outside the scope of its parent class and so it probably means that other things are using it). If this is the case, then it might make more sense to make it a standalone enum.</li> <li>I find it <code>ThirdPartyResponseCodes.Success</code> easier on the eyes rather than <code>ThirdPartyIntegrationInterface.ThirdPartyResponseCodes.Success</code>. There is no reason why you cannot name the enum appropriately to provide context and thus make it a standalone enum.</li> <li>I would imagine that the same reasons for not using public inner classes also apply to public inner enums. First of all, if you have an inner class, it may mean that your outer class might benefit from refactoring. Perhaps your outer class is trying to do too much? On the flip side though, there is the benefit of encapsulation and limiting scope, especially if you can make the argument that the inner class only makes sense in the context of the outer class (which should go without saying if it is private). If it is a public inner class, then that probably means that its scope extends past the outer class and thus it would need to be pulled out.</li> <li>If you really do need to use a public nested enum then you should document exactly why you would need it (I haven't found a reason to do so yet) and why it is better to leave it as an public nested enum and not a public standalone enum.</li> </ul>
    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.
    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