Hi,

Is there any interest in having enums as class constants?

I'm often finding cases where I would like to have an enum inside of a
class, but don't want a free-floating enum that's basically like
another class.

When dealing with state, it's nice to have a human readable const to
represent that state, but I always feel like they should be grouped
together.

For example:

class SSHClient {

   public const COMMAND_RESULT_SUCCESS = 0;
   public const COMMAND_RESULT_FAILURE = 1;
   public const COMMAND_RESULT_UNKNOWN = 2;
   public const COMMAND_RESULT_TIMEOUT = 3;

   // ...

}

These constants would make sense as an enum, but they make no sense
outside of the SSHClient class that uses them.

It seems that enums would be useful as class constants. There's a lot
of cases where a class implements a state machine and needs statuses,
but those status flags should be local to the class, not shared between
classes.

Example:

class SSHClient {

   public const enum CommandResult
   {
       case Success;
       case Failure;
       case Unknown;
       case Timeout;
   }

   // ...
}


// Usage:

SSHClient::CommandResult::Success

Reply via email to