0

I have a User model class with get and setter methods which also implements Parcelable

public class User implements Parcelable
{
    private String email;

    private String password;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

Now should I create a separate UserSingleton class or implement in User model class itself.

public class UserSingleton
{
    private static User instance = null;

    private UserSingleton()
    {
        // Exists only to defeat instantiation.
    }

    public static User getInstance()
    {
        if(instance == null)
        {
            instance = new User();
        }

        return instance;
    }
}

Please suggest me the preferred approach

Sharath
  • 2,348
  • 8
  • 45
  • 81

0 Answers0