Home
Copyright Yaroslav Sivokhin, all rights reserved.
Android AsyncMvp framework helps to create module system base on MVP template and message-based architecture. Framework includes core module and helping modules:
AsyncMvp is a design pattern framework for the quick development of Android applications. The framework architecture is based on a message-based system.
AsyncMvp is a Design Pattern Framework for the quick development and strict structuring of Android applications. AsyncMvp has been used in several applications with different logic and the number of this applications is constantly growing, such as: Geo Tasker, 24minutes and Beacon
Before describing the goals of the framework it’s necessary to explain some terms. <u>Module</u> - a component of the framework which realizes some technology, for example, data exchange over HTTP, data caching. Module is a model in terms of MVP template.
Layer is an interface of module for message handling like making some computations with message and executing module methods.
View is an instance of Activity or Service or View class in Android OS.
When we talk about components of framework we mean Views and Models(Modules) of MVP template.
The goals of framework are:
Intent: The message-based system allows the interchange of messages between modules and applications views.
Motivations (forces): This design pattern can be applied to solve a great variety of problems in many diverse scenarios. A messaging paradigm is widely used in nature and the real world. Messages are interchanged all around us. Entities are constantly sending, receiving and processing messages. Human beings for instance: when we watch TV, listen to music, talk over the phone, or communicate via the internet. Right now, you are reading this written message. Since applications seek to model the real world, it is only natural to design and write applications using a messaging approach. As a consequence, software engineering processes are significantly improved by the use of the message-based system.
Participants:
Message Sender: View or Model(usual View) in MVP template that sends the messages for getting or updating data.
Message Recipient: View or Model in MVP template(usual Model) that receives the input message and may produce a reply (output message) after processing it. The message may contain any type of information. View or Model is instructed to perform computations based on the input message. It is common to interchange messages between View and View or Model and Model.
Presenter: Intermediary that transfers the message from the sender to the recipient. The sender and the recipient don’t need to be concerned about how the message is transferred (communication protocol, message format, encryption/security mechanism, etc.) and the transformations performed on the message along the way. Message is sent according protocol. Special class contains list of protocols and their description. Several modes of communication are possible: asynchronous and two-way messaging.
Message: instance of Message class which contains information that needs to be sent to the recipient. Message.what field defines the protocol of message. Information can be stored in Message.arg1, Message.arg2 and Message.obj fields and also in a Bundle which is accessed through Message.getData() method. Two messages are usually involved: input message and output message (or reply message). The reply message is not required.
The message-based system is implemented using the AsyncMvp model messaging interface (ModelLayerInterface) and Android view message interface Handler.Callback. The ModelLayerInterface consists of 3 methods one of them is required to implement:
public interface ModelLayerInterface {
public void init(Context context);
public boolean handleMessage(Message msg);
public LayerStatus getStatus();
}
And Handler.Callback interface consists of a single method handleMessage(Message msg). The messaging interfaces are simple but powerful. One method is all that is needed! It acts as a universal messaging interface that applies to framework components.
Messages are sent asynchronously and placed in a message queue until you are ready to "process" them. MBS is able to handle the complexities it associated with, asynchronous messaging and multithreading.
Framework modules are executed in a separate independent thread. This is a natural representation of the real world: each component (entity) is a self-contained unit able to execute independently for the rest of the system.
Messages are processed asynchronously using the component’s own independent thread. This capability is implemented in the context of the AsyncMvp framework via a messaging queue.
The module does not need to add logic to manage multithreading if you do not want it. You can also decide to send a message back asynchronously establishing a two-way communication.
Copyright Yaroslav Sivokhin, all rights reserved.
Questions & Comments
Leave a comment
Log-in now or register for a free account.