KenAragorn / create_flutter_provider_app

A boilerplate project created in Flutter using Provider and Firebase.
MIT License
400 stars 117 forks source link

Why not use repository layer to access firestore ? #1

Open rubensdemelo opened 4 years ago

rubensdemelo commented 4 years ago

Why not use repository layer to access firestore ?

KenAragorn commented 4 years ago

Hi @rubensdemelo,

Thanks for the inquiry.

Actually we are using repository layer. Let me explain.

If you look at the class FirestoreService, it contains all generic CRUD operation. For example: Creating/Updating a document: Future setData(...) Deletion: Future deleteData(...) Getting a list of collection: Stream<List> collectionStream({..._ However, all the above is generic, and don't need to hard-corded any document path. So, in my view, the FirestoreService is a Repository.

For FirestoreDatabase, it is the actual Service layer representative that expose additional business logic, which uses Repository.

So, in future, lets say we added a new section and a new document for user to store images, I can create a separate collection and new methods in FirestoreDatabase without touching the FirestoreService.

Perhaps a better ways that we can improve the code, is to refactor the class name from FirestoreService to FirestoreRepository and make it as an Abstract class that contains basic CRUD method that any sub-class can access it. And then, the class FirestoreDatabase will extends the renamed FirestoreRepository to access the method.

Still, I would like to hear more from you and see area that can further improve (future roadmap). :)

rubensdemelo commented 4 years ago

Thank you for clarification. Appreciate.

KenAragorn commented 4 years ago

Most welcome. :)

Side note, I have updated the project - now it support multi-language control, which is also commonly used and needed for any app. Please refer to the updated README.md.