Does implementing multiple interfaces violate Single Responsibility Principle?

前端 未结 3 2116
轻奢々
轻奢々 2021-02-08 01:22

From Wikipedia:

Single responsibility principle states that every class should have a single responsibility, and that responsibility should be entirely

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-08 01:31

    I would say not by itself. A class can have one responsibility, but do multiple things in the process, and implement one interface for each set of things it needs to do to fulfill its responsibility.

    Also, interfaces in Java can be used to say things about what properties the class has (for example, Comparable and Serializable), but not really say anything the class's responsibility.

    However, if a class implements multiple interfaces, each of which corresponds to one responsibility, then that would be a violation of that principle.

提交回复
热议问题