DEV Community

Amila Rangana
Amila Rangana

Posted on • Updated on

Nation Job Connect - DevLog #3 - Follow the Dependancy Inversion Principle (DIP)

Today we are working on saving and reading data from Firebase Firestore DB to implement nation's VacantShift and saving Applications for published VacantShift.
While we are designing our solution, we have identified some classes to be stored in the Firestore DB such as 'VacantShift', 'Nation', 'User'. In the 'VacantShift' class we have defined few parameters like 'id', 'nation', 'time', 'shiftType', etc.. But we have defined VacantShift and Nation collection also in the Firestore DB and within the VacantShift document we have defined 'nation' parameter type as 'reference'. To read VacantShift object from the DB, we have to add datatype of the 'nation' parameter as 'DocumentReference' which is a Firestore dependant class. Then it will be cause for breaking fifth principle of the SOLID principle since there will be a tight coupling between Firestore service and our App.
Then we discussed and came up with the solution to replace the 'reference' datatype with the 'String' and stored the 'id' of the 'nation' document in 'VacantShift'. Then we could read nation details by id without violating the SOLID principle.
Anyway, though we have limited time, we are expected to follow the programming best practices and proceed to meet the deadlines.

Top comments (0)