Default implementations

It is very common to share default implementations between your objects, and only implement the difference when needed.

Let's first start by adding a new service to our factory for registering for localization services. Luckily for us, CoreLocation is the same SDK for both iOS and macOS, so we're able to share our implementation between the two platforms, as follows: 

protocol UserLocationService {
func getUserLocation(done: (CLLocation) -> Void)
}

struct CommonUserLocationService: UserLocationService {
func getUserLocation(done: (CLLocation) -> Void) {
// TODO: Implement me
}
}

Let's now add it to our ServicesFactoryType:

protocol ServicesFactoryType {
func getPushService() -> PushNotificationService
func getUserLocationService() -> UserLocationService
/* Add more services here as your project grows */
}

Now, we have our UserLocationService interface, with a default implementation, and we've added the requirement to our protocol. However, our current code will break, as neither iOSServicesFactory nor macOSServicesFactory implement func getUserLocationService() -> UserLocationService.

There are multiple ways to move forward, knowing that this implementation is shared by all platforms.