Practical Singleton & Dependency Injection question

前端 未结 5 1032
名媛妹妹
名媛妹妹 2021-02-07 10:11

Say I have a class called PermissionManager which should only exist once for my system and basically fulfills the function of managing various permissions for various actions in

5条回答
  •  迷失自我
    2021-02-07 10:40

    The singleton pattern is not bad by itself, what makes it ugly is the way it's commonly used, as being the requirement of only wanting a single instance of a certain class, which I think it's a big mistake.

    In this case I'd make PermissionManager a static class unless for any reason you need it to be an instanciable type.

提交回复
热议问题