Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider dropping the use cases and interface with the repositories directly #32

Open
erawhctim opened this issue Jul 8, 2024 · 1 comment

Comments

@erawhctim
Copy link

Why not have the ViewModel fetch data directly from a repository instance? (Aside from "because clean code says so", of course)

@jarvislin
Copy link
Owner

jarvislin commented Jul 11, 2024

Hi @erawhctim,

Why not have the ViewModel fetch data directly from a repository instance? (Aside from "because clean code says so", of course)

This is simply my preference.

From an Android developer's perspective, the MVVM + Repository architecture allows for writing less code. From an app user's perspective, the results are identical. From a product standpoint, Clean Architecture enables a clearer understanding of our business logic, making communication with non-technical stakeholders smoother.

In my past work experience, I've often needed to communicate with product managers, designers, and even marketing colleagues. They don't need to know the implementation details (usually in the repositoryImpl), but they do need to understand the use cases.

This is why, even if it means writing more code, I prefer using Clean Architecture.

Btw, your approach is also listed in the official recommendations. Check out this link: Recommendations for Android architecture.

Consider dropping the use cases and interface with the repositories directly

Removing the interface compromises the independence of unit tests. Interfaces allow us to use mocks or stubs, ensuring tests focus solely on the unit's logic without dependencies on external systems (See the dependencies). This keeps tests reliable, fast, and easy to diagnose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants