Protocol Oriented Programming (POP) with MVVM
To explain briefly what MVVM and POP is:
Protocol OrientedProgramming:Protocols are extremely powerful and can transform the way you write code. Here, you’ll explore the ways you can create and use protocols, as well as use protocol-oriented programming patterns to make your code more extensible and maintainable.Model:The model is something referred to as the domain object. The model speaks to the actual information and additional data we are managing.Ex:1. Card (last4Digits, cardType, cardName, expiryDate and so on)2. Employee(name, phoneNumber, department, email and so on)The way to recall with the model is that it holds the data. Business rationale is ordinarily kept separate from the model and typified in different classes that follow up on the model. Now and again, a few models may contain approval.ViewModel:ViewModel associates with model and furthermore gets ready observable(s) that can be seen by a View. ViewModel can alternatively give snares to the view to pass occasions to the model.One of the imperative execution methodologies of this layer is to decouple it from the View, i.e, ViewModel should not know about the view who is dealing with.The viewModel additionally shows techniques, charges, and different focuses that help keep up the condition of the view, control the model as the consequence of activities on the view, and trigger occasions in the view itself.View:The view part in this example is to watch a ViewModel to get information keeping in mind the end goal to refresh UI components as needs are.
Now let’s dive into actual coding:
Here is the sample code for different types:
