The previous (Android design casually said simple practice (module Division)) Example of the application store design to explain how to do the module division. Module division mainly depends on the first is the business requirements, specifically how the business. The App Store includes two businesses that show Users applist, and download apps. The second is the operating environment, on the Android platform, there are ANDROIDSDK to provide API support such as sockets. As a result, the module was largely reissued to 5 modules. (Of course, the image loading can be presented in extra, open source components to do, but here to illustrate how to design, temporarily not mentioned.) There are also downloads that can take advantage of open source components), respectively, as follows:
Module 1 UI Module , which is responsible for displaying information and user actions, main classes, recommendactivity responsible for data presentation and accepting user actions. Recommendinterface, responsible for the underlying data callback. (Here is just an example, the download is not mentioned)
The invocation relationship between these three classes is as follows: (my viso seems to have no activation part of the function can not be used only to dictate)
1 initializes the Recommendinterface instance Recommendbase instance inside the Recommendactivity oncreate. and inject the recommendinterface into the recommendbase.
2 recommendactivity then sends instructions to Recommendbase to call Getpageviewdata and other methods to request data.
3 When the user clicks download. Gotodownloadapp is the time when Recommendbase began to call Startdownloadapp.
Okay, the calling process for the UI module is basically here.
Module 2 Dispatch module. Responsible for overall business scheduling. The main classes include the following:
Giant complex. But let's go over the relationship of each class invocation.
1 initialization of the module is the initialization controller. Controller initializes the Controllerdownloadappinfosinterface, and Controllerbase. The controller injects the controlelrdownloadappinfosinterface into the controllerbase. Initializes the controllerdownloadappinterface when the controllerbase is initialized.
2 key points, how the UI module interacts with the dispatch module.
2.1 Recommendbase Inside initializes the controller and Controlleruiinterface. and inject the recommendinterface into the controlelruiinterface.
2.2 When recommendactivity receives the user instruction, Recommendbase receives the instruction call controller. And when the asynchronous result comes out, Controlleruiinterface calls Recommendinterface. And the UI interface is updated to the user by Recommendinterface. (This shows that the news is a circle from Recommendbase.) )
3 page data loading. When the controller receives an instruction from recommendbase, it calls Controllerbase to launch the load template and the data getviewdatabytempid. When the underlying gets to temp and data, it notifies controlelrdownloadappinfosinterface that the interface is in the callback controller. Controller calls Createviewdata. The Controlleruiinterface call is then called to give the data to the UI.
There is also the download process. This is not a deduction. But the main is to see how the module between the call, that is, how reasonable combination.
Will find that the upper-level business and its own dependent interface are a comprehensive set of complete business. And the dispatch layer also completed a set of complete business.
The third module, data parsing module, is responsible for the network applist data and template parsing and combination.
Key points, how to interact with the dispatch module
In the controllerbase of the dispatch layer to initialize the class Dataworkmanager, the dispatch layer has the template and the app data, call SetData, and then call Getviewdatabytempid on the template data can or.
That is, in the dependency class of the dispatch layer, initialize its own interface, and implement the business according to the method of the dependent class.
But this is a business unit that cannot achieve the overall business.
The fourth module, the network request module.
Key points, how to interact with the scheduling layer.
First initialize the Nettaskmanager and Nettaskresultlistener inside the controllerbase. and Controllerdownloadappinfosinterface injected into the nettaskresultlistener.
Then start calling Downloadtemplatebyid (). Asynchronously, the result is fed back to Controllerdownloadappinfosinterface by Nettaskresultlistener. This message is handled by Controllerdownloadappinfosinterface.
Module 5 Download module, still need to say? I don't think so.
In fact, a reasonable combination depends on how you dispatch between modules. The module provides an interface because first, his module does not need other modules to care about. Just call it's interface. Second, if there is a problem with his implementation, the problem will inevitably be solved in this module. There is no need to change anywhere else. So in principle, regardless of how the module changes, it does not allow the interface to change.
Each module has its own dependency class, but if other modules have similar implementations, the provided interface is bound to make an adaptation to the former module's dependencies to achieve seamless connectivity. The above example is very simple. Basically there is not much to rely on and the interface between the adaptation, but the actual work is more.
Finally, I'm sorry to say that the above example is a lot of flaws, many places just say is very simple, very rough, redundant, even wrong. Just want to get some benefit.
Android design casually speaking simple practice (reasonable combination)