This question already has an answer here:
My question is about the following. I know that classes should have only one responsibility and not even two. for example in user class, we shouldn't have function which registers users and another one which sends emails. It's better to make email sending in seperate classes, since if we don't, user class will have two responsibility.
Question 1) have you used MVC framework for example Laravel? there, if i make a class, there'll be 5 functions(insert,create,get,put,delete). Do you think this is the single responsibility? since it has 5 functions. I think yes because it still handles users.
Question 2) Why do you think this principle is good? I think the following:
a) because it's better to have different kind of responsibilities separately as It's super better to test those codes differently.
b) we can use those separated classes in other contexts.
c) It's said that class should have only one reason to change. Why is it bad that if user class has two responsibilities, and I need one of them to change, I always come to users's class. why is this bad?
Please if you don't mind, just agree with me and provide me more world-life scenario if possible. Thank you so much.
Aucun commentaire:
Enregistrer un commentaire