Search code examples
androiddesign-patternsinterfaceandroid-architecture-componentsandroid-viewmodel

Using interfaces for ViewModels?


I am currently integrating architecture components into my app according to the official documentation and the sample apps provided by google (sunflower and todo-app). I realized that none of these use interfaces for ViewModels (the sunflower app does not even use interfaces for repositories).

My question is: is it reasonable to just omit the interfaces for ViewModels (including advantages and disadvantages)?


Solution

  • Is it reasonable to just omit the interfaces for ViewModels?

    The below is quite general and applicable not just for ViewModels.

    Advantages:

    • less code

    Disadvantages:

    • won't be able to use most of the well-known design patterns;
    • won't be able to properly unit test classes (no mocking);
    • won't be able to properly use dependency injection frameworks;
    • code refactoring when using another concrete implementation.