What is the One Class, One Responsibility Principle?

后端 未结 5 2031
广开言路
广开言路 2021-01-12 22:14

I would like to learn about the One Class, One Responsibility principle. I have found some articles about it, but without examples. It would help me if you can giv

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-12 22:39

    The principle is exactly what it says it is, not much more. One class should only have one responsibility. It can be difficult to define responsibilities though. An example could be a "DatabaseHandler"-class that handles all database requests in an application.

    Further reading: cohesion.

提交回复
热议问题