Linked Questions

Popular Questions

How to not violate Single Responsibility Principle?

Asked by At

I am new to programming and I am learning design things.

I was taught that SRP is super important such that every class should have one responsibility. Thus, I wanted to inherit responsibilities from other classes. But then, I realized java doesn't allow multiple inheritances, but only interfaces. I think the problem of implementing multiple interfaces is that you have to write the methods inside the one class that implements the interfaces anyways. So you have to go to the class that implements the interface to fix the method. Then isn't it considered to violated SRP?

In short, I want a class A, say dog, that construct a thing and need methods B(bark), C(eat), and D(sleep) about the A. How do I do that without violating SRP?

Related Questions