lundi 3 octobre 2016

Should a class named `User` be an implementation of Singleton Pattern?

Today I read a lot of articles about how Singleton Pattern is bad, such as

  1. violating single responsibility principle

  2. inability to subclass

  3. inability to use abstract or interface classes

  4. High coupling across the application

  5. make unit test difficult

And then I remember I have a program with a class named User which has field userName and password and something else related to User. In my conceive the program should only have one user instance, which is created when a human logins in my program. Based on this, should I insist design User class as Singleton Pattern, or is there any good design conceive I should use?

Aucun commentaire:

Enregistrer un commentaire