ConformanceLocked

public protocol ConformanceLocked

Protocols that inherit this protocol are considered locked and can be conformed to and implemented only inside the TomTomSDK.

Important

This protocol should not be implemented by any other framework except TomTom components. The source and runtime stability aren’t guaranteed otherwise.

Note

to test code that depends on APIs that conform to ConformanceLocked, isolate these APIs with an additional abstraction (wrapper). Build your implementation with this abstraction as a dependency. Here is a way to do it by creating an additional protocol:
// An example of protocol that provides necessary functionality in the TomTomSDK.
public protocol Planner: ConformanceLocked {
    func plan()
}

// An abstraction from the client side that provides the same interface but is not locked.
// Every TomTomSDK protocol might need this protocol clone.
// Use this type to pass it in the application and in tests.
protocol ClientPlanner {
   // The method should have the same signature
   func plan()
}

// Wrapper implementation on the client side that will contain TomTomSDK dependency
// but conform to the non-locked protocol
class ClientWrapperPlanner: ClientPlanner {
    let planner: Planner
    init(_ planner: Planner) {
        self.planner = planner
    }

    func plan() {
        planner.plan()
    }
}

// An example of the production code that needs to be tested.
// Use `ClientPlanner` in your production code, so you can mock it.
struct PlannerViewModel {
   init(_ planner: ClientPlanner) { }
   //
   // ...
}

// In production code
let planner: Planner = ... // getting real planner
PlannerViewModel(ClientWrapperPlanner(planner))

By depending on `ClientPlanner` a `PlannerViewModel` instance can be tested
by mocking all its dependencies. To mock its dependencies, replace `ClientWrapperPlanner` with a
mocked implementation of `ClientPlanner`.
  • A requirement to restrict access for implementing this protocol.

    Important

    This property should not be implemented by any other framework except TomTom components. The API and runtime stability aren’t guaranteed otherwise.

    Declaration

    Swift

    static var conformanceLock: ConformanceLock<Self> { get }