Steve
Steve
And it seems you can't subclass enum.
Steve Luke wrote:Break what out into a separate class?
The enum? Yes, just make the enum a top level class definition instead of a class.
The display name? Probably. But I don't understand the reasons. I think a display name member is a very consistent part of the enum and is properly encapsulated the way it is. It isn't like the toString method ties the enum to be used with the command line at all, it just provides a well formatted name, and how you display that name is entirely up to you.
Steve
Steve Luke wrote:Oh, I see. No, you can't declare a base enum type. You might be able to do it using a Utility class or aggregation. But like I said, I think the displayName is well encapsulated inside the Breed itself.
The benefit of aggregation would be the ability to modify the Helper class without modifying the enum class, to switch to different / extend helpers etc... But it seems like a lot of work to isolate the displayName
John de Michele wrote:Bai:
Sorry, I don't think that will work with real enums. Why don't you create an interface like this:
Then, have your enums implement that interface:
You can then access your enums like this:
John.
I'm not quite sure what you mean by displayName being well encapsulated inside the Breed itself? As I said, what happens when you want to do Cat breeds instead of Dog breeds? Or in addition to?
That's kind of what I'd like to do, but I want to have all of the logic in one place instead of having to copy it for each enum subclass.
John de Michele wrote:Well, the solution that I suggested will handle that case, since if you do it the way that I suggested, you can access them as DisplayableEnums.
John de Michele wrote:Unfortunately, it won't work that way, at least if you use enums. Implementing a single-method interface doesn't seem like too much work to me.
John.
Steve
Bai Shen wrote:
John de Michele wrote:Well, the solution that I suggested will handle that case, since if you do it the way that I suggested, you can access them as DisplayableEnums.
-nods- But Steve's didn't, and that's what I was confused about.
Steve
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |