5 notes on MVP architecture pattern for Android

                                                           Image credits Macoscope

MVP (Model View and Presenter) is an architectural pattern inspired by the popular MVC pattern.

MVP addresses two main points :

  1. Make views as dumb as possible. The dumber the better.
  2. Make each layer loosely coupled and easily testable in isolation.

I am using MVP in one of my production project and have used in some dem0 apps. Here are my 5 notes on using MVP for android.

  1. Package Structure :

Android project contains lots of code and files even for application of medium complexity. Even when not following MVP I have found that arranging the project files in such a way that files that are accessed together are put in same package is more efficient and intuitive than any other approach.

What I prefer doing is create separate package for separate verticals of the app and put all related files like activities, fragments, views, presenters, adapters etc in that package.

ex. packages like add task, view task, list task for a To-Do app.

2. Libraries that are useful for MVP :

In MVP you want your model and presenter to be independent of the life cycle of view. For this, you can use dependency injector library like Dagger2.

Other than that, using RxJava and reactive programming principles for creating presenter is also becoming increasingly popular.

Libraries you can use for this purpose are : RxAndroid and EventBus.

3. Managing Remote and local data sources in the Model :

Android apps have to fetch data from the server. At the same time fetched data must be cached to make the app usable offline and increase the speed.

What I prefer doing is to create three model classes :

1. Remote Data Source

2. Local Data Source

3. Data Repository

All presenters talk to Data Repository class. Data repository model contains references to Local and Remote data repository and calls data from either according to situation.

As the name suggests Local Data Source deals with cached data and disk storage whereas Remote Data Source deals with API calls and responses.

4. User Experience is the top priority :

One thing that we all have to keep in mind that the real test of application is, if it is able to provide user a nice experience.

At the end of the day, user only notices the user experience of the application and not the architecture used. So if you have to make some design sacrifices to make the UX better, do it.

The real test of the machine is the satisfaction it provides to the mind. There is no other bigger test.

5. Testing Advantages :

Main motive behind MVP pattern was to make the testing of layers easy.

Basic idea is to keep the presenter and model android free, so that they can be tested without Android instrumentation by the JVM itself.

Views can then be tested by Android Instrumentation tests.

Mockito and Espresso can come handy for testing purposes.

Conclusion :

MVP, in my opinion is so far the best way to architect your android application project. It simplifies many issues like testing and making views lighter. Combine it it RxJava and dependency injection and you’ve got a nice recipe for android projects.

I am learning more about RxJava and testing frameworks will share my views on that soon.

Thanks.

How Mobile Devices Can Change the Educational Technology and Education?

Educational technology is growing rapidly and thus is catching everyone’s attention. At the same time mobile devices are part of are lives from a long time now. Students and teachers are increasingly embracing tablets and e-book readers in their personal lives.

Accessibility of educational technology is one of the biggest barrier that we are facing. Mobile devices are best way to make this problem less serious.

Advantages of mobile devices to be used as platform for ed-tech :  

  1.  Easy accessibility and availability.
  2. Inexpensive than other tools like desktops and laptops.
  3. Smaller is size and thus easy to carry.
  4. Rich application environment to distribute content.
  5. Highly accepted device by all people.

“It’s about better engaging students in class, seeing how instructional support areas can use the devices in terms of working with students, and finding out if faculty and staff can use them to be more efficient and effective,” says Lisa Young, an instructional design and educational technology faculty member at SCC.

With growing popularity of mobile devices we have enormous possibilities to enhance the current education system. We can put content on e-books, applications etc. The current generation is so innate with mobile devices that use of mobile as a platform for ed-tech will only make it more intuitive and fun for them.

 

“Like any new technology, it takes a while to see where it fits,” says Ron Bonig,

Of course this will take some time. We are still in phase where educational technology is not that crosses everyone’s mind as a necessity. Some people still think smartphones are hindrance to education. But i very firmly believe that string development programs in this field will cause them to go with the flow.

Despite its potential mobile computing is yet to reach the mass educators and students as a platform. But who knows we are at the starting of a revolution that will change the education scene forever!