Comparing VIPER vs. MVVM
Recently I started playing with VIPER architecture. Although I was quite hesitant trying it out, it turns out it's not all that bad as I expected. It'e certainly better than traditional MVC iOS architecture in terms of testability and separation of concerns. However, I found it consistently annoying to have to make bunch of files even for small features. It's after all a price paid to get more testability out of components.
I am still waiting to get all the code uploaded to GitHub. But in meantime I will make a tiny comparison with MVVM to give you a better idea about these two architectural paradigms.
|Contains 3 components. Model-ViewModel-View||Contains 5 basic View-Interactor-Presenter-Entity-Router|
|Provides less granular view of components by encapsulating non-view related logic into viewModel||Provides more granular view by encapsulating non-view related logic into presenter, interactor and router|
|View is responsible for routing||Router part of components is responsible for routing|
|MVVM generally uses ReactiveCocoa, RxSwift or equivalent reactive components to communicate||VIPER generally uses delegate and protocol pattern to facilitate communication between interactor, presenter and view|
|Unit testing is performed for View-Models as it contains the main business logic. (You can test views too, but this component is usually detached from View-Model)||Unit testing is performed on Presenter and interactor and views|
|Contains less boilerplate code since all the components are essential in architecture||Contains more boilerplate code since in small use-cases developers still have to make presenter, interactor and router even though they may not be necessary|
|Model part handles network or database models||Entity part handles network or database models|
|Data model layer is associated with ViewModel which performs storing and fetching data from local database cache. ViewModel in turns informs view about any updates in incoming data||Data model layer is associated with interactor. Data model informs interactor about data change, which in turns informs presenter. View gets this information from presenter.|
I found these differences from my tiny VIPER experience. Let me know if you have additional things to add to list or there are any differences you do not agree with. I would love to hear your thoughts on these architectural differences.