I have a class which is responsible for sending and receiving messages. Messages are sent by using myInstance.send(message, channel) and messages are received by registering a MessageListener with a channel to listen on.
I would usually just call this something fairly generic such as MessageManager but I have recently read Naming Classes - How to avoid calling everything a "<WhatEver>Manager"? which made me try and find another name. The closest I could come to a good name was MessageDispatcher which doesn't really convey the fact that also receives messages. Are there any generally used names for a class of this nature?
I tend to like the names Publisher and Subscriber when dealing with messages (see more info on publish/subscribe pattern here).
If your message handling is similar to that a neat and tidy naming strategy could be the to separate the whole thing into these interfaces.
// Publisher of messages
public interface MessagePublisher {
void send(Message m, Channel c);
}
// Subscriber of messages
public interface MessageSubscriber {
void messageReceived(Message r);
}
// Handles registration
public interface MessageSubscriberAware {
void registerMessageSubscriber(MessageSubscriber s, Channel c);
}
// The "glue" - the concrete implementation
public class MessageDispatcher implements MessagePublisher, MessageSubscriberAware {
// Impl
}
The concrete implementation of this that could be named MessageDispatcher, it is aware of the subscribers and can therefore distribute the published messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With