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.



LFS101x : Introduction to Linux on edX

It was this summer when I saw this course LFS101x being offered on edX  by The Linux Foundation.  Both the terms Linux and edX excited me . So I decided to take this course.

My experience with prior online courses

I have taken few online courses on edX and coursera . In both the cases I loved the excitement and knowledge they provide. They were also fun learning and thus worked well for me.

My background prior to taking this course

Before taking this course I was an average newbie to Linux . All I was having was curiosity and a little knowledge of Linux . Thus I found this course perfect for me.

As being a programmer , I used Linux just for programming purposes. And wanted to expand the arsenal.

The journey of the course

The course started on 1 August ’14 . I took this course on its very first offering.  It was a self-paced course and they provided all the chapters in advance. All chapters were divided into small sections . Each section ends with couple or more questions . There were video demonstrations of all major Linux shell commands which were great to catch the concepts.

It took me 10 days to finish this course  , when I decided to take the final exam which I found pretty easy.

The course content was updated and discussion forums on edX were helpful.

In epitome  it was a great learning  experience and   you will feel like a linux super user at the end 😉 .

What this course demands?

It’s easy and alluring to declare that you’re “starting” an online course , but it is equally important not to dwell on it for too long especially if this is your first online course.

That doesn’t mean this course requires great effort  . All this course demands is commitment , dedication and will to learn.

Final words

It was great to be a part of such a massive learning group . Both the knowledge you gain and the community you get in touch with thrills you .

I highly recommend all of you to take this course.

They also provide an Honor Code certificate for free after scoring more then 70% in the final exam.

You can have a look at my certificate here.

Starting c/c++ programming in Linux.

So, guys this post is just a kick off to my blog.

This post is about coding in c or c++ in Linux . So, if you are a beginner looking to get your hand on coding in c or c++ in Linux, this will be of great help.


1.You can use gedit or i recommend you download Sublime Text for Linux.

2. Select your language as c/c++ and code and save the file.

3. Open the terminal and use cd (change directory ) command to get to the directory in which you have saved your program .

4. Now, type ” gcc  -o name name.c” and hit enter. This will create the object code of your program and compile it and reports the error( if any )  which can be read by your computer,

5.To run your program ,type “./name”. And hit enter.

6. And you are done.