Continuing with the discussion of design patterns for software development, this article discusses techniques for implementing the MVVM design pattern for Android application development. MVVM is one of the design patterns that we can use in Android application development.
We have learned a lot from what design patterns are, what are their benefits, and what design patterns we can apply. Maybe you are confused about the MVVM design pattern mentioned above because it was not discussed in the previous design pattern article. Don’t worry! We’ll discuss it after this. So, read to the end!
What is the MVVM design pattern?
Pattern Design Tips
Design Pattern MVVM Layer
MVVM is a GUI based application creation
Architecture that focuses on separating the code for business logic and application appearance. In its application, MVVM is divided into several layers, namely Model, View, and ViewModel. See the discussion of the three layers below.
The model layer is the models or Thailand Mobile Number List entities that represent the data that will be used in the business logic. Generally, if we use Kotlin, the classes in it are POJOs or plain old Java objects and data classes.
The last ViewModel layer is the ViewModel whose job is to interact with the model and the existing data will be passed to the view layer.
Tips for Implementing MVVM
The creation of the MVVM design pattern took many factors into consideration. Google, as a mecca for implementing this design pattern, has created many APIs and special documentation to help developers implement it.
However in field practice, we can still see many
Errors that will make the implementation poor and may even cause interruption or even damage to the application process being developed.
So, what common mistakes have we found and what steps can we take to overcome them? Let’s discuss them one by one.
Separation of event and observer data
Executing the above code will not have much FIND List problem, the data will be displayed successfully. The problem arises when there is a change in behavior. In the application, such as a change. In orientation, where the data already displayed is lost because. The data request is made again and waits for the dat.
The above code is normal and there is no problem. But what if the data is only displayed when the event is raised? For example, when a button is clicked. Some cases of calling watch functions are shown below
Using the code above, we can avoid creating Observe instances over and over again.