mrsegev / MovieNight

MovieNight is a sample Android application that uses the clean architecture approach and is written in Kotlin.
772 stars 144 forks source link

Why are there 2 classes that are exactly the same #2

Open linxydmhg opened 6 years ago

linxydmhg commented 6 years ago

This is a question, not an issue. I'm curious, why are there 2 classes that have exactly the same signature: MoviesRepository and MoviesDataStore here: https://github.com/mrsegev/MovieNight/tree/master/domain/src/main/kotlin/com/yossisegev/domain

Is this a standard approach by duplicating the class? I imagine if you had a very large project with lots of models and methods it would become a bit confusing..

Lewiscowles1986 commented 6 years ago

You're going to kick yourself when you see this https://github.com/mrsegev/MovieNight/blob/089768c55cb26281a08812f3d65e315fa26b2422/data/src/main/kotlin/com/yossisegev/data/repositories/MoviesRepositoryImpl.kt

Essentially the repository delegates to the datastore in a factory-ish way. Whilst it's not imperative they share the same signatures, it probably made writing by one person easier.

In a team environment, this is less likely to happen. Also if you reduced to a single signature, you'd never know if people were binding to the data store directly (what the repository is designed to stop happening so you can switch stores / store implementations).

There is a great write-up, which is how I got here, which seems to cover this https://proandroiddev.com/a-guided-tour-inside-a-clean-architecture-code-base-48bb5cc9fc97