Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I guess most of the above answers are valid, but I'm not sure any are correct.</p> <p>The correct answer is, you very rarely switch in an OO language, it indicates you are doing your OO wrong. In this case, it's a perfect indication that your Enum class has problems.</p> <p>You should just be calling Console.WriteLine(mood.moodMessage()), and defining moodMessage for each of the states.</p> <p>If a new state is added--All Your Code Should Adapt Automatically, nothing should fail, throw an exception or need changes.</p> <p>Edit: response to comment.</p> <p>In your example, to be "Good OO" the functionality of the file mode would be controlled by the FileMode object. It could contain a delegate object with "open, read, write..." operations that are different for each FileMode, so File.open("name", FileMode.Create) could be implemented as (sorry about the lack of familiarity with the API):</p> <pre><code>open(String name, FileMode mode) { // May throw an exception if, for instance, mode is Open and file doesn't exist // May also create the file depending on Mode FileHandle fh = mode.getHandle(name); ... code to actually open fh here... // Let Truncate and append do their special handling mode.setPosition(fh); } </code></pre> <p>This is much neater than trying to do it with switches... (by the way, the methods would be both package-private and possibly delegated to "Mode" classes)</p> <p>When OO is done well, every single method looks like a few lines of really understandable, simple code--TOO simple. You always get the feeling that there is some big messy "Cheese Nucleus" holding together all the little nacho objects, but you can't ever find it--it's nachos all the way down...</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