Search code examples
ooplanguage-agnosticmultiple-inheritancesolid-principlessingle-responsibility-principle

Does implementing multiple interfaces violate Single Responsibility Principle?


From Wikipedia:

Single responsibility principle states that every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class.

Does that mean implementing multiple interfaces violates this principle?


Solution

  • 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.