You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current design of the CustomerIO class relies on static methods, making it difficult to write unit tests and achieve Dependency Injection. Converting static methods to instance methods will make the class more testable and flexible.
Proposed Changes:
Convert static methods in CustomerIO to instance methods.
Continue to use the existing private constructor const CustomerIO._(); to ensure that CustomerIO remains a singleton.
This approach will maintain the singleton behavior while offering greater flexibility for testing and modularization.
Example:
Before:
// Using static methodCustomerIO.subscribeToInAppEventListener(_handleInAppEvent);
After:
// Using instance method through singletonfinal customerIO =CustomerIO.instance;
customerIO.subscribeToInAppEventListener(_handleInAppEvent);
Practical Example with InAppMessagesBloc:
Suppose you have an InAppMessagesBloc that handles incoming in-app messages. In the current architecture, mocking CustomerIO for testing the Bloc is difficult.
Description:
The current design of the
CustomerIO
class relies on static methods, making it difficult to write unit tests and achieve Dependency Injection. Converting static methods to instance methods will make the class more testable and flexible.Proposed Changes:
CustomerIO
to instance methods.const CustomerIO._();
to ensure thatCustomerIO
remains a singleton.This approach will maintain the singleton behavior while offering greater flexibility for testing and modularization.
Example:
Before:
After:
Practical Example with InAppMessagesBloc:
Suppose you have an
InAppMessagesBloc
that handles incoming in-app messages. In the current architecture, mockingCustomerIO
for testing theBloc
is difficult.Before:
After:
With the proposed changes, we can inject a mock or stubbed
CustomerIO
instance into theInAppMessagesBloc
for better unit testing.Benefits:
The text was updated successfully, but these errors were encountered: