I have spent quite some time learning all possible design patterns but I cannot find the ideal one for the following case. I am developing an iOS app where we are using multiple analytics tools like Google Analytics/Facebook Analytics and it is possible that in the future we will add some more (our company is obsessed with measuring :D).
Each of them uses their custom SDK to log an event which comes with its own method to send an event and its own parameters. I would love to refactor it and create a module where adding new analytics tool wouldn't lead to code smell and in best case scenario there would be a central place which would dispatch the events at once.
I was thinking about this:
- Defining a protocol
AnalyticsProtocolwhich requires implementation of
AnalyticsEventclass for every tool (
GoogleAnalyticsEvent) which conforms to the protocol above and implements
sendEventmethod. Each of these classes would have its own
- Cental dispatch class which takes an array of
id<AnalyticsProtocol>objects and calls
sendEventon every single one of them.
Do you have any better ideas? Thanks.