How to implement a service-oriented architecture in Objective-C?

I am wondering which of the following would be the correct use / implementation in Objective-C of a service oriented design:

The first version refers to static languages ​​using protocols (interfaces):

// 
// get the cloud service from our service provider
// 
id<CloudServices> myService = [ServiceProvider serviceWithProtocol:@protocol(CloudServices)];

The second version does not use protocols, relying on the fact that Objective-C is actually dynamic:

// 
// get the cloud service from our service provider
// 
CloudServices *myService = [ServiceProvider serviceWithClass:[CloudServices class]];

Obviously, the difference is that CloudServices is an interface or protocol, and we mean that ServiceProvider can be configured to return different implementations of CloudServices.

So my question is which style to choose, and why?
Thank.

+3
source share
1 answer

, . , ServiceProvider , , . , ServiceProvider , , . , , , serviceWithProtocol:.

: , , , .

+1

Source: https://habr.com/ru/post/1787048/


All Articles