Connection Manager: Singleton or not Singleton?

心不动则不痛 提交于 2019-12-08 11:21:33

I went through similar thinking as you and ended up with this pattern:

ConnectionManager [singleton] - responsible for maintaining a connection to the server and submitting & receiving requests

ConnectionQueue [singleton] - Stores a stack of Requests waiting to be fulfilled

Request - Created each time something is needed from the server. It contains all the request data (urls, params etc) and a reference to the delegate.

Response - A container for the data retrieved from the server along with the original request.

Hooking it all together...

  1. The ConnectionManager is started at startup and it creates the ConnectionQueue
  2. When a call to the server is needed create a Request object, pass in all required params and add it to the ConnectionQueue
  3. The queue lets the manager know there's a request that needs to be processed
  4. The manager removes the request from the queue & makes the call to the server
  5. Data is received
  6. The manager creates the response and sends it back to the delegate.
DreamOfMirrors

You can see this other post:. I think it can be useful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!