Quantcast
Viewing all articles
Browse latest Browse all 8

Strategy vs Publiser-subscriber pattern

Let’s say I have a channel endpoint where I receive messages. Because I want to process messages in a different way depending on its Header property, rather than create a massive switch I create different strategies with the contract:

interface IMessageHandler
{
    String MessageHeader {get;}
    void Handle(Message msg);
}

So then I can add new handlers for new messages without altering what is already there. But this leaves the door open to have multiple handlers that handle the same message kind. Or with a little change, make a handler able of handling several message kinds:

interface IMessageHandler
{
    Boolean CanHandle(Message msg);
    void Handle(Message msg);
}

But… then it starts to look a lot to the pub/sub pattern, where the message Header property would be the topic to which handlers subscribe…

Where is the line that sepparate both patterns?


Viewing all articles
Browse latest Browse all 8

Trending Articles