Hat focuses on separating business logic

Architecture tand application appearance code. In its application, MVVM is divided into several layers, namely Model, View, and ViewModel. See the discussion of three layers below. The model layer is the model or entity that represents the data that will be used in the business logic. Generally speaking, if we use Kotlin, the classes in it are POJOs or plain old Java objects and data classes. Views differ from the previous layers in that this layer contains the application’s UI and controls how information is displayed. This layer will contain classes such as Activity and Fragment. The last ViewModel layer is ViewModel whose job is to interact with the model and existing data will be passed to the view layer. 

Tips for implementing design

 Pattern was created with many factors in mind. Google, being the 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 ineffective and may even lead to interruption or even damage to the application process being developed. So, what common mistakes do we see and what steps can we take to overcome them? Let’s discuss ws number list them one by one. Separation of event and observer data There won’t be much problem executing the above code and 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 that has been displayed is lost because the data request is issued again and waits.

Separate the function that requests

 For the data request to complete execution. To solve the above problem, just  the data and the object you want to observe, as shown below. c The above code is normal and has no issues. But what if the data is only displayed when an event is raised? For example, when a button is clicked. Some situations where observing functions are called are shown below. Using the above code Canada People we can avoid creating Observe instances over and over again. Utilize the state of your data The final tip is to use state data. Eits, but before we leverage state data, what kind of situation do you want to solve? Let’s take a look at the following example of ViewModel class.

Leave a comment

Your email address will not be published. Required fields are marked *