Design patterns

There is no need to reinvent the wheel and there is no need for us to repeat ourselves. This is exactly what the Don't Repeat Yourself (DRY) software development principle dictates. A design pattern is a solution for a common problem, and such a pattern can be used in many places across your app. It is the methodology that we can trust, which will help us to speed up the development process. Patterns could help us develop high-quality software with minimal effort. They also can help us deal with the separation of concerns. Some well-known patterns are the Model View Controller (MVC) pattern, the somewhat similar Model View Presenter (MVP), and the Model-View-ViewModel (MVVM) approach.

There are some great books about design patterns and it is beyond the scope of this book to have a detailed look at all of them, but the MVC/MVP is of particular interest because it is used the most for mobile development. The idea behind the pattern is to separate the UI from the business logic and data from the logic. When you have a closer look on the structure of most Android or iOS apps in Android Studio or in Xcode, you will notice some parts of this pattern already. A controller gets data from another layer. This layer can be a client or a repository class. For example, it will get its data from an API or from a local source. The controller communicates the obtained data through a model (or view model) to the user interface: