Controllers should have a single responsibility?

Asked

Viewed 79 times

0

As well as the classes and objects of an application, mine controllers should have a single responsibility?

Example.

I have my controller Cliente, who has all relations with my model Cliente.

I also have the model Contato.

It would be right for me to have mine actions ContatoPorCliente, ExcluirContatoCliente, etc. within my controller Cliente? Those actions are called in the view Cliente.

My question is why sometimes we have screens that have several Tabs(Tab) in a form. Client who has Contact, Financial Data, etc...

  • Yes, that’s right, but when there is a Customer Contact reference, where you do your actions?

1 answer

1


I see no problem in doing this, as long as the referred contacts have some relationship with the client, making explicit that they are a client’s contacts.

If there are other ways, other than through the client view, to manipulate contacts, then yes, I think the separation becomes more necessary.

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

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

  • My question is why sometimes we have screens that have several Tabs(Tab) in a form. In the example I mentioned, contact can be for everything, Client, Provider, among others

  • In this case, I think there should be a single rule. If in each tab there can be items that are client aggregates, and in another there are items that relate to various other parts of the system, then I prefer to separate everything already. A system with fewer rules, and therefore simpler, has more chances to survive.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.