Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 813
Chander Shivdasani Avatar asked Aug 07 '12 23:08

Chander Shivdasani


1 Answers

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.

like image 101
Dennis Meng Avatar answered Sep 30 '22 09:09

Dennis Meng