Where should I define business logics in VIPER Architecture in iOS, Swift

Viewed 734

I have used different architectures and I'm kind of new to VIPER architecture. I used to do all the business logics in the Model Class. Is this the best practice for VIPER as well or is there any standard way of doing this in VIPER architecture, specifically in iOS, Swift?

2 Answers

The business logic in a VIPER module resides in the Interactor, whereas the Presenter contains view logic and prepares content to be consumed by the view. As a simple example, if your Presenter needs to display information it would ask your Interactor to fetch it from a data source.

I found this article to be pretty useful for getting started with VIPER: https://www.objc.io/issues/13-architecture/viper/

As explained in https://theswiftdev.com/the-ultimate-viper-architecture-tutorial the presenter zone is where business logic is implemented. The interactor zone is for the actual acquisition from sensor, database, network, etc. Yes, at some level of rudimentary concepts the actual correct operation of the sensor is a kind of business logic; the operation of the database (especially if it has stored procedures) is a kind of business logic; obeying the networking protocol's rules & formats is a kind of business logic, but that 'business' is a low-level business of infrastructure the bread-&-butter app-domain business for which the higher-order software app is being written in VIPER.

Hence, the presenter zone is where business logic for the app should reside, with the interactor focused solely on what it takes to accomplish the operation of the infrastructural mechanics of the data acquisition itself.

Related