0

I'm new to TDD and I'm trying to apply Single Responsibility Principle to an API.

I'm using an API that returns multiple feed subscriptions in a single event. Each subscription can be differentiated from another because the Event Handler contains an id field. what I want to do is make a wrapper to the API which can manage the subscription updates such that a Subscription class only receives event updates relevant to it as determined by the id field of the event fired by the API.

Now I have wrapper to the API where I implemented the Subscribe() method such that it returns a Subscription class where it contains a Subscription.Updated() event. I keep a record of the Subscription s in a Dictionary so I can notify each Subscription based on their id.

My problem is how do I pass the Subscription Updated event parameters from the API to a particular Subscription and raise the Subscription.Updated() event? I've read that I can make a public OnUpdate method (which i've done in previous projects) but they say that this breaks encapsulation and SRP.

Or am I approaching this incorrectly? Is there a more elegant way to do it?

Additional info:

Request a feed from the API:
void Feed.Subscribe(id, SubscriptionParamaters)
Where id will be used to identify which response belongs to which subscription.

You can get subscription updates by
Feed.Update(id,UpdateValueArgs)

stromms
  • 161
  • 5
  • If you are doing multiple feeds subscriptions in a single event, isn't that in-and-of-itself violating single responsibility? Each different event can be a cause to change the class rather than a single reason to change the class. – SASS_Shooter Jul 03 '13 at 20:01
  • it's not me, it's the API. That's why I'm trying to make a class that will manage the subscriptions and notify the proper objects. To make it clearer, here's how the API is used. let's call the api Feed. `1. Feed.Connect() //establishes connection between the API and the program` `2. Feed.Subscribe(id, SubscriptionParamaters) requests a feed` Once you do that, the API will return any feed updates on one event which you need to subscribe to get incoming data. The event has the signature `Feed.Updates(id,UpdateValueArgs)` – stromms Jul 03 '13 at 22:48

0 Answers0