vendredi 30 décembre 2016

What are the drawbacks of combining Singleton pattern with the Facade pattern?

I am developing an android library, the structure of this library is such that there is a main class(called Myservice) that makes use of a couple of other classes to expose certain functionality to developers. As I understand it this is the Facade pattern. Myservice class looks like this

public class Myservice
{
    private RequestManager requestManager;
    private DBManager dbManager;
    private SecurityManager securityManager;

public Myservice(Context context)
{
    requestManager = new RequestManager();
    dbManager = new DBManager(context);
    securityManager = new SecurityManager();
}

public void initializeSecurity(SecurityConfig securityConfig)
{ //init security}

public Service deliverService(String param)
{
    ....
}   

}

Now, I want the developer that consumes this Myservice class to be able to create only one instance of the class only. This can be achieved using the singleton pattern However, I have read that using the singleton pattern can cause problems down the road with testing and other issues and also there is the issue of instantiating a singleton with arguments. I want to know if there is a better way of achieving the singleton effect or if I should really be worried about the issues that come with singletons in this scenario.

Aucun commentaire:

Enregistrer un commentaire