-
Notifications
You must be signed in to change notification settings - Fork 252
SDK Architecture
The SDK is transitioning to a MVVM / Clean architecture. However there is no view layer since there is no UI that lives in the SDK. The SDK also utilizes a custom implementation of dependency injection.
All business logic in the SDK should be added to the domain layer as use case classes. Each use case is limited to a single public function that performs a single action. Use cases are injected to any classes that depend on them.
Example use case: GetReturnLinkTypeUseCase.kt
All state in the SDK should be stored in a Repository class. The repository can either store data in memory or handle persisting data to disk. All repositories in the SDK are treated as singletons to ensure consistent data across the SDK. Repository singleton instances should be injected into any classes that depend on them.
Example repository: AnalyticsParamRepository.kt
The SDK has a custom dependency injection solution where default values for dependencies are used in class constructors.
Example:
class PayPalClient internal constructor(
private val braintreeClient: BraintreeClient,
private val internalPayPalClient: PayPalInternalClient = PayPalInternalClient(braintreeClient),
private val merchantRepository: MerchantRepository = MerchantRepository.instance,
getReturnLinkTypeUseCase: GetReturnLinkTypeUseCase = GetReturnLinkTypeUseCase(merchantRepository),
private val getReturnLinkUseCase: GetReturnLinkUseCase = GetReturnLinkUseCase(merchantRepository),
private val getAppSwitchUseCase: GetAppSwitchUseCase = GetAppSwitchUseCase(AppSwitchRepository.instance),
private val analyticsParamRepository: AnalyticsParamRepository = AnalyticsParamRepository.instance
)