Pop Pop - 4 days ago 4
Android Question

MVC pattern with Firebase

I have a simple question. I am developing an Android application that uses as backend Firebase realtime database. I was wondering if can it be said that my app is built following the MVC pattern, although I do not have my own logic, my own server, I am using the API from Firebase. Thanks!


Yes, you can use MVC pattern with Firebase. With Firebae it's even simpler. You can create a model class in which you can declare all the variables you need. This can include also other classes. Create all the constructors that you need. Add public setters and public getters and you'll have your complete model class or your POJO. Don't forget to add the no argument constructor needed for Firebase.

Here is an example of an user model class with only two fields.

public class UserModel implements Serializable {
    private String userEmail;
    private String userName;

    public UserModel() {}

    public void setUserEmail(String userEmail) {this.userEmail = userEmail;}
    public String getUserEmail() {return userEmail;}

    public void setUserName(String userName) {this.userName = userName;}
    public String getUserName() {return userName;}

Every change that is made in your Firebase database is triggerd in real time in your user interface.

I recomand you reading the official documentation for Firebase. Here is how to add Firebase to your Android Project and here is how you can set up Firebase Realtime Database for Android. And here is how you can use FirebaseUI for Android.

Hope it helps.