How to use navigation component with VIPER architecture?

601 Views Asked by At

I'm trying to learn how to use VIPER with android from this tutorial https://www.raywenderlich.com/5192-android-viper-tutorial but in the end of tutorial it said it's hard to implement the router layer which a core layer of the architecture .. is there anyway to implement viper and it's router layer across navigation component

1

There are 1 best solutions below

0
On BEST ANSWER
  • Router is navigation; navigation is router. You should not think the way that you phrased the question, because “implement … router … across navigation component” will mislead your thinking. https://TheSwiftDev.com/the-ultimate-viper-architecture-tutorial is succinct and clear in establishing good thinking regarding VIPER, although even it could be even better if it drove the following point home even more intensely: 100% of the messaging & data-structures/entities & concepts interlayer between V I P R layers must be strictly app-domain concepts that have nothing to do with Apple-think or Android-think or Microsoft-think. All of the {Apple-frameworks-think, Android-think, Microsoft/UWP-think} must be quarantined within each the V I R layers and never appear at all in the P and E layers.
  • It is best to learn navigation from VIPER and MVVM-C examples. The C of MVVM-C is almost exactly the same as the R of VIPER; both are responsible for navigation. There are multiple example/sample apps (as well as few open-source full-fledged apps) that use either VIPER or MVVM-C. Search for them via Bing or Google. You can learn the R of VIPER just as well from the C of MVVM-C if MVVM-C was done properly with strictly app-domain concepts/data-structures/messaging/entities flowing between VM & C without contamination between VM & C layers from {Android-think, Apple-think, Microsoft-think}. Even if messaging between VM & C layers is muddled with {Apple-think, Android-think, Microsoft-think} in some sample/example MVVM-C app, you can still learn from it by translating the operating-environment-pollution interlayer to strictly-app-domain information flows interlayer, but that is pretty much the how-to-convert-my-app-to-reactive/Rx technique by inserting {RxKotlin, RxSwift, RxScala, ZIO+CatsEffect} effect/outcome-centric reactive information flows interlayer instead of some {Android, Apple, Microsoft}-centric delegate/callback mechanism.
  • Because VIPER and MVVM-C and Clean all need a pure app-domain interzone way of messaging that has {Apple-think, Android-think, Microsoft-think} quarantined within each layer/zone (e.g., keeping Apple-think/Android-think/Microsoft-think ways of representing UI strictly quarantined within view layer in VIPER; keeping Apple-think/Android-think/Microsoft-think ways of representing navigation strictly quarantined within router layer in VIPER), quite often design teams choose to use an event-driven functional-programming-esque reactive way of representing the strictly app-domain messaging that is flowing between each of the V I P R layers in VIPER (with E entities being the lingua franca of representing app-domain concepts between layers). As such, you can often use such reactive frameworks (e.g., RxSwift when in Apple world; ZIO or Cats Effect or RxScala when in the Scala school of thought within Android world; RxKotlin when in the Kotlin school of thought within Android world) as the primary search word for sample or example apps for that reactive framework, then cherry picking from the list of results the example or sample apps that are VIPER or MVVM-C, such as in https://AwesomeOpenSource.com/projects/rxswift where the description indicates which ones teach VIPER's or MVVM-C's R or C techniques that you will find quite instructive.