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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With