Let's say I am writing a class in Cocoa to act as a proxy to a server. To represent the current state of the connection, consider the enumeration:
enum
{
MyConnectionStatusDisconnected = 0,
MyConnectionStatusConnecting,
MyConnectionStatusConnected,
MyConnectionStatusCount
};
typedef NSUInteger MyConnectionStatus;
I may have it live in my proxy class like so:
@interface ServerProxy : NSObject
{
MyConnectionStatus connectionStatus;
}
That's fine, but what if I want to figure out a user-readable interpretation of the connection status? I might have a static function like this:
+(NSString*)statusStringForInt:(MyConnectionStatus)status;
At this point I'm quickly leaving the realm of object-oriented programming.
What would be the best way to refactor this enum into a class hierarchy?