Controllers should have only one responsibility?

0

Just like an application's classes and objects, should my controllers have a single responsibility?

Example.

I have my controller Cliente , which has all the relationships with my model Cliente .

I also have the model Contato .

It would be right for me to have my actions ContatoPorCliente , ExcluirContatoCliente , etc. inside my controller Cliente ? These actions are called in view Cliente .

My question is why sometimes we have screens that have multiple Tabs in a form. Customer that has Contact, Financial Data, etc ...

    
asked by anonymous 28.04.2014 / 14:49

1 answer

1

I do not see problem in doing this, as long as the mentioned contacts have some relation with the client, making explicit that they are contacts of a client.

If there are other paths, other than Client View, to manipulate contacts, then yes, I think separation becomes more necessary.

You know, code organization patterns exist to help move the point in the project where the code is done ... the separation of responsibilities provides for a need that usually comes up during the maintenance phase (and which is a nightmare): the coupling, so it's better to make a code with low degree of coupling from the beginning.

If contact is something that exists only as something that is part of the client, then the coupling will not be high anyway ... otherwise it is better to separate already.

    
28.04.2014 / 15:02