简体   繁体   English

在Android应用中设计网络层

[英]Designing a networking layer in Android app

I am working on an android app with some networking aspects. 我正在研究具有一些网络方面的android应用程序。 There are places in the app that, when a button is pressed, a call is made to a server with a response full of data coming back. 应用程序中的某些位置,当按下按钮时,会调用服务器,并返回充满数据的响应。 My question is regarding creating a robust flow where i have my network calls separated in their own class and all i do is instantiate a networking object such as new MyNetworkHelper(accessClientServer) and give it the name of a client server. 我的问题是关于创建一个强大的流程,在该流程中,我将自己的网络调用分隔在各自的类中,而我要做的只是实例化网络对象,例如新的MyNetworkHelper(accessClientServer)并为其指定客户端服务器的名称。 This object would then instantiate the appropriate object (ClientServer or StudentServer or TeacherSever etc) to do with accessing that server and doing any database saving and returning a response to the MyNetworkHelper object which would return to the button that was pressed. 然后,该对象将实例化适当的对象(ClientServer或StudentServer或TeacherSever等),以访问该服务器并保存所有数据库,并将响应返回到MyNetworkHelper对象,该响应将返回到按下的按钮。

Is this the best way to do this kind of task? 这是完成此类任务的最佳方法吗?

What you propose is not unreasonable but could be more standardized using standard patterns such as your helper being a Singleton (and your additional servers as well if they are intended to be used in such a fashion). 您提出的建议并非没有道理,但可以使用标准模式(例如,您的助手为Singleton(以及如果您打算以这种方式使用的其他服务器),则可以更标准化)进行标准化。 I would recommend you pick up a beginner book in Design Patterns and Architecture. 我建议您阅读《设计模式和体系结构》中的入门书籍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM