So, since I did not know which of the answers to approve, I sent the author part of the code and asked him what he thought about it. Here is the conversation (block from it. My normal text):
Hi Michael,
What is the difference with having only one listing? You would not have three singletons, but three more uniquely defined objects:
Of course, this can be done, but then I will have to invent a name for it (for example, ConcreteSignal), my chosen encoding avoids :)
enum Signal { Cancel, Subscribe, Send; }
I think this is also thread safe, and if you really want to have a common interface that you can use with objects, for example, you can do it like this:
enum ConcreteSignal implements Signal { Cancel, Subscribe, Send; }
You could do as you did above, however I would say that they [Cancel, Subscribe, Send] are no more specific than the Request (which is also a signal): https://github.com/reactive-streams/ reactive-streams-jvm / blob / v1.0.0 / examples / src / main / java / org / reactivestreams / example / unicast / AsyncIterablePublisher.java # L49
In addition, it may also facilitate the use of Enum methods to list all the possible Signals that failed, since Request is not a signal. Has the meaning?
Indeed, in Scala, you would prefer to do this with Object, but in Java it is very rare to see something like your implementation. I was just curious that I lacked some neat feature in Java. But if I understand correctly, is it because you are more comfortable with this implementation, since it is closer to Scala, your preferred language?
I suppose this is a little, but the singleton-as-enum-pattern in Java is pretty well known, so the only “weird” thing would be to have a separate “enumeration” for each of the “Cancel”, “Sign” and “Send”, but how I explained earlier, since the request cannot be encoded the way I chose the more "Scala -y" version.
So, if the "Request" does not need any parameters, I would do as you suggested: enum Signal {Cancel, Request, Sign, Send}
Mystery solved: -).