What is the One Class, One Responsibility Principle?

后端 未结 5 1993
广开言路
广开言路 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:53

    Every thing in a class should be related to what the class should be responsible for.

    If it is a class named MailSender, it should only know how to send the mail. Code that creates the mail content should not be inside it.

提交回复
热议问题