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
AnalyticsProtocol
which requires implementation ofsendEvent
method - Defining
AnalyticsEvent
class for every tool (FacebookAnalyticsEvent
,GoogleAnalyticsEvent
) which conforms to the protocol above and implementssendEvent
method. Each of these classes would have its owninit
method. - Cental dispatch class which takes an array of
id<AnalyticsProtocol>
objects and callssendEvent
on every single one of them.
Do you have any better ideas? Thanks.
allTheAnalytics.sendEvent()
and implement that one method using all of the concrete SDK classes. Or do you expect to use different combinations of Analytics SDKs for different programs and are looking for an easy way to construct all of those combinations?