Partial for separating events and methods

4

I have seen in a system a separation of the methods in a partial and the events in another in UserControl and Window as the example below:

"Pessoa.xaml.cs"
public partial class Pessoa: UserControl
{
    //Construtor
    //Somente Eventos Exp: Click dos botões
}

"Pessoa.cs"
public partial class Pessoa
{
    //Somente Métodos Exp: Metodo Inserir

}

Is this correct to do?

Do you have any performance gains?

Or should it have been made just for organization?

    
asked by anonymous 20.04.2016 / 15:58

1 answer

3

Only organization, does not change anything at execution.

Some people consider that partial should only be used by code generation tools (which is often the case for events), so the generated part is in a file that the programmer should not by hand and the which he can tweak is in another file.

Others are not so radical, after all, it is rare to be a problem. Separation may occur through other factors, even separation of responsibilities within the team.

What you should avoid is to simulate classic inheritance, trait , or things like partial . Even this I would say just to avoid, not to never do.

    
20.04.2016 / 16:04