‫Hello my friends, and welcome back.
‫In this video I'm going to talk about a very important concept in Android.
‫Very very important concept in Android and mVVM architecture.
‫Model view ViewModel I want from you to fully focus with me, because I'll use this architecture pattern
‫in the next projects.
‫Imagine you have a cool remote controlled robot and you want to make it to do different tasks such as
‫walking, dancing, and waving.
‫To do this, we need to tell the robot what to do and show its actions on the screen.
‫Here's how the mVVM works with our robot.
‫The model.
‫The model is like the robot's brain.
‫It knows how to perform all the tasks but doesn't do anything by itself.
‫It just waits for instructions.
‫In our case, the model is like a list of tasks the robot can do, such as walk, dance, and wave.
‫The second part is the view.
‫The view is like the remote control that you use to interact with the robot.
‫It has buttons for walk, dance, and wave.
‫When you press a button, for example the wave button, it tells the robot what to do and in this case,
‫the robot will wave.
‫In our example, the view is like the buttons on your remote control.
‫The third part is the view model.
‫The view model is like a translator between the robot's brain and the remote control.
‫It understands the tasks the robot can do from the model and knows how to talk with the remote control,
‫which is the view when you press a button on the remote control, the view model translates your action
‫into a command that the robot's brain understand.
‫For example, if you press the wave button on the remote control, the view model tells the robot brain
‫to wave.
‫Let's see how it works.
‫By a step by step, you press the wave button on the remote control.
‫The remote control or the view sends a message to the view model saying, hey, I want the robot to
‫wave.
‫The view model, which is the translator, receives the message and looks at the list of tasks model
‫to find out how to make the robot wave, the view model tells the robot robot's brain, which is the
‫model to start waving, and the robot's brain, which is the model, starts waving and you see the robot
‫waving on the screen.
‫So in simple terms, mVVM helps us control our robot or application by separating the brain model.
‫The remote control, which is the view, and the translator, which is the view model.
‫This separation makes it easier to manage and control what our robot or application does.
‫Just like using a remote control to make our robot perform different tasks.
‫Let's see.
‫mVVM in Android Model View ViewModel mVVM is a template of a client application architecture proposed
‫by John Guzman as an alternative to MVC, MVC, and MVP patterns when using data binding technology.
‫mVVM is an architectural pattern commonly used in software development, particularly in building user
‫interfaces.
‫mVVM is designed to separate an application into three distinct components, each with its specific
‫responsibilities model view and view model its concept to separate data presentation logic from business
‫logic by moving it into particular class.
‫For a clear distinction, let's dive into these components of the mVVM and let's see the layers.
‫The separate code layers of mVVM are model, view and ViewModel model.
‫This layer is responsible for the abstraction of the data sources.
‫Model and ViewModel work together to get and save the data.
‫The model represents the application's data and business logic.
‫It encapsulates the data you need to work with, such as user information, database records, or data
‫retrieved from web service.
‫It doesn't contain any code related to the user interface or how the data is displayed.
‫In Android, models are often represented as data classes or entities.
‫Is that defined the structure of the data.
‫The second layer is the view.
‫The purpose of this layer is to inform the view model about the user's action.
‫This layer observes the view model and doesn't contain any kind of application logic.
‫The view is responsible for representing and presenting the data to the user and capturing user interactions.
‫It corresponds to what the user sees and interacts with an application.
‫In the context of a mobile application and mobile app development, the view can be considered as the
‫user interface components like buttons, text fields, images, and layout structures.
‫Views are typically designed using XML layout in Android or XML, HTML, CSS.
‫In web development, the third layer is the view model.
‫It exposes those data streams which are relevant to the view.
‫Moreover, it serves as a link between the model and the view.
‫The view model acts as a bridge between the model and the view it holds.
‫The presentation logic manages the data for display and exposes data to the view, in a format that
‫can be easily rendered.
‫The view model is responsible for transforming and formatting data from the model into a form that is
‫ready to display in the view.
‫It also handles user interactions and prepares data to be sent back to the model of any updates.
‫The view model doesn't have direct knowledge of the view.
‫Instead, it provides data and methods that the view can bind to.
‫In Android, View, model is often implemented as a class that extends a view model from the Android
‫architecture components it serves configuration changes like screen rotations and helps in managing
‫the UI related data.
‫And we talked about the view model in the previous sections.
‫Now let's jump into Android Studio and learn about these layers and about the mVVM architecture.