“A design that doesn’t take change into account risks major redesign in the future.” ― Erich Gamma
Design patterns is one of those few things that only after you’ve experienced it you realize how you lived without any care about it. And let me get straight to the point , this article is more of a list of very helpful and concise resources than an actual guide (you can find tons of step-by-step guides with code in medium) to the Model-View-Presenter Design pattern/Architecture for android. This is for the novice’s who want to take their first bite at MVP in android and assumes you are familiar with Version control systems , like Git.
Let’s start by getting to know MVP and its siblings in the land of design patterns through an excellent article by Realm MVC-MVP-MVVM by Eric Maxwell . Before we get our hands dirty, i want you to check out Martin Fowler’s Blog on Design Patterns. He has written extensively on this topic and has an amazing book titled Patterns of Enterprise Application Architecture . Now there is a design pattern of special interest for us , the Repository pattern , which you can read here and here . That book itself is a treasure trove , so get a copy if you can. Now that we have the Why , lets move on to the How and the Where .
“Any fool can know. The point is to understand.” ― Albert Einstein
As a starting point , i went for the Google Android Architecture Blueprints Github Repository where you can find a single TODO app implemented using different architectures and frameworks. But initially the whole structure was kind of alien to me , so i searched for videos where they implement MVP in android and i came across two amazing channels , DryCode and WiseAss . These channels are highly recommended if you’re just starting out in android. Check this specific video by DryCode where he does a live coding session Refactoring an Android App - #1 - Intro to the MVP pattern series. Now, download/clone a copy of the architecture blueprints repository (preferably the todo-mvp branch if your’re new to android) and get familiar with it while you’re watching the videos .
NOTE: Now there’s one thing i would suggest you to start with , and that is TDD(Test Driven Development) especially when you’re new to android , because once you get an idea of the cycle in which testing is interweaved into development , in the after stages the whole process won’t be intimidating. There are tons of resources(including great books)on TDD in the internet, you can find them being used in the videos i’ve linked .
Coming back to the architecture blueprints repository , i choose the todo-MVP-RxJava branch as i wanted to know learn how RxJava works with MVP , and it took some time as i didnt have much experience with either of them. So, as i have decided to build an app , i thought why not make it a serious project and release it in the Google Play Store. In the end i did publish it and i have to say it was a satisfying and an awesome learning experience.
If you’d like to see the App it can be found here PerusalQuotes. I plan to write about that in a later post.
Now using the architecture blueprints repository , you can easily understand what goes behind the scenes and how all the dots get connected. It uses the repository pattern for the Model part (thanks to the link earlier , we are well aware of it). And if you’re new to Data Storage in android , i suggest you read about it here Data Storage Android . I tried the amazing Room Persistence Library for easy handling of SQLite in android. The View and Presenter part is pretty straightforward. The reason i highlight the architecture bluprints repository is that , it is the best possible repository out there for architecture in android and they use the latest libraries and best practices. You’ll also learn Testing as they cover it extensively.
I pretty much needed only these resources to get a good grasp of what MVP is and also a great deal of what design patterns does. After getting to know design patterns , i definitely will use it in all of my future projects. Hope this article was of value and do share your thoughts below.
Thank You 😄
Tip: Here is a great read and step by step guide to MVP , Mindorks MVP Articles.
I ❤️ Design Patterns