从Android UI中抽象Firebase [英] Abstract Firebase from Android UI
问题描述
有没有解决这个问题的方法?
Firebase和UI之间没有固有的耦合(除非您使用 FirebaseUI
)。典型的解决方案是在某种Service / DAO类中封装Firebase数据库访问(例如使用Dagger注入到UI类中),并且在该类中的方法返回RxJava Observable(这也很好地使得可以嵌套firebase查询....例如,如果做一些相当于加入)
I'm facing with issue that Firebase as Realtime Database works great while we connect it with Activity or Fragment. But trying to separate from view elements and create some abstraction for it (because e.g. we want to replace it while testing or in the future) becomes quite hard, especially trying to implement MVP pattern.
Are there any solutions for this issue?
There should be no inherent coupling between Firebase and UI (unless you're using FirebaseUI
). Typical solution would be to encapsulate firebase database access in some kind of Service/DAO class (injected in to UI classes using Dagger for example)....and have methods in that class return RxJava Observable (this also nicely enables making sets of nested firebase queries....for example if doing something equivalent to a "join")
这篇关于从Android UI中抽象Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!