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 "
Answer
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.
No comments:
Post a Comment