Useless interfaces

后端 未结 25 1628
南笙
南笙 2020-12-14 01:42

Why would you ever use an interface if you are only going to have one implementation of it?

25条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 02:40

    In some cases, for visibility: you might want certain parts of the code to see the concrete class and have access to the setters, and some others to see only getters: give them access to the interface only.

    This cannot always be achieved with public/protected/private.

提交回复
热议问题