What is the correct system design when working with a third-party API?

This Joubert blog post just opened my eyes. I reviewed many design patterns in Java and other languages. But Objective-C is a rather unique language.

Let's say that in the project we are talking with a third-party API, like Dropbox or Facebook. What I have done so far is to combine everything related to a third-party API into a singleton class. Therefore, I can access the class from anywhere in the controllers of my view. I can just go for example:[[DropboxModel sharedInstance] uploadFile:aFile]

However, as noted in a blog post, this is inefficient and leads to spaghetti code and poor module testing. So, what is the best way to develop a system so that it is modular and easy to use?

+3
source share
3 answers

I would dispute the idea that singletones lead to spaghetti code and are ineffective. However, the problem of testing modules is legal, and the one-dimensionality does reduce modularity, since they are really just bizarre global variables.

I like the idea of ​​Jauber about injecting a singleton instance into the controller from the application delegate (which is itself a singleton gem). I think the same approach will work for you.

, , - , API "" API , - API. ​​ .

+2

, , , DropboxModel, :

#define DBM [DropboxModel sharedInstance]

<...>
[DBM uploadFile:aFile];
0

. , , (, ), .

, , , . "" - , , .

. () , , , , . - , /// - , .

if you don’t need a library everywhere, then I think it’s also useful to wrap what you need in order to minimize dependencies (more and more important in large projects).

if you use the library everywhere, then you can also use calls without an abstraction layer.

0
source

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


All Articles