Sobes.tech
Middle

Where is the business logic stored in the application?

sobes.tech AI

Answer from AI

Business logic can be stored in various layers of the application, depending on the chosen architecture.

In typical architectural patterns for iOS (MVC, MVVM, VIPER):

  • MVC (Model-View-Controller): Business logic is often distributed between Model (responsible for data and its processing) and Controller (coordinates interaction between Model and View). This can lead to "thick" controllers.
  • MVVM (Model-View-ViewModel): Business logic is primarily stored in the ViewModel. The ViewModel contains presentation logic and business logic not directly related to UI. The View binds to the ViewModel.
  • VIPER (View-Interactor-Presenter-Entity-Router): Business logic is concentrated in the Interactor. The Interactor contains the core rules of the application and operations not related to data presentation. The Presenter manages the Interactor and formats data for the View. The Entity represents data. The Router handles navigation.

Additionally, in more complex architectures, there may be separate layers or modules specifically dedicated to storing business logic:

  • Domain Layer: An independent layer from UI and infrastructure, containing core entities, rules, and business operations.
  • Service Objects: Classes that perform a specific business operation or set of operations.
  • Use Cases (or Interactors): Specific implementations of business scenarios, often used in clean architecture or VIPER.

The choice of storage location depends on the application's complexity, testing, and maintainability requirements. The goal is to make business logic as independent of UI and infrastructure as possible for better reusability and testing.