Viper - DevOli/Marvel-chars GitHub Wiki

What is Viper?

To better organize all the classes, structs and Enums, the Clean Architectures first showed up to save the functionalities inside smaller layers which communicate with each other by using delegations and completions, each one with a single responsibility, this way accomplishing the SOLID principles. The Clean concept was first presented in Uncle Bob's book, which is a new way grouping the code classes into separated layers. It presumes a scheme where each layer does not have any knowledge of how the other one’s work.

How It Works?

VIPER is the industry's best and unbeatable when it comes to creating iOS architecture patterns with a model based on modular code-based theory. The roles of five VIPER architecture components are as follows:

1. View

The interface layer, which includes UIKit files, is referred to as View (including UIViewController). In a more decoupled architecture, it's obvious that UIViewController subclasses should belong to the view layer. Things are pretty much the same in VIPER as they are in MVVM: views are in charge of showing what the presenter asks them to and transmitting user feedback back to the presenter.

2. Interactor

This part includes the business logic outlined in the application's use cases. The interactor is in charge of retrieving data from the model layer (via network or local database), and it is completely independent of the user interface. Since network and database administrators are not included in VIPER, they are handled as separate dependencies.

3. Presenter

This component contains view logic for formatting data that will be displayed. This is part of the job that the ViewModelController in our example does in MVVM. The presenter takes data from the interactor, generates a view model case, and passes it along to the View. It also responds to user feedback by requesting more information or returning it to the interactor.

4. Entity

In other architectures, it shares some of the model layer's obligations. The interactor and data managers handle entities as basic data structures with no business logic.

5. Router

The application's navigation logic. It does not seem to be a big layer, but if you have to reuse the same iPhone views in an iPad app, the only difference is how the views are displayed. This protects your other layers, and the Router is in charge of the navigation flow in each case.

Viper vs MVVM

When compared to MVVM, Viper has a few main differences in responsibility distribution:

  • It adds the router layer, which is in charge of the navigation flow and removes it from the View.
  • Entities are simple data structures that move the access logic from the model to the interactor.
  • The duties of the ViewModelController are shared by the interactor and the presenter.

Benefits and Disadvantages

Benefits of Using the VIPER Framework

  • The most adaptable architecture for large teams.
  • Code is decoupled for reusability and testability.
  • The number of merge conflicts is reduced.
  • Makes the codebase appear to be the same.
  • Creates user interfaces that are both simple and well-defined.
  • Complicated tasks are made simpler.

Disadvantages of using VIPER framework

  • Communication between components is rigid.
  • Third-party SDKs are not supported.
  • A few performance problems have been found by developers.

Viper Flow

Viper

Viper Directory Structure

ViperDir