Partial for separation of events and methods

Asked

Viewed 61 times

4

I saw in a system a separation of 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

}

This is right to do?

Has some performance gain?

Or it must have been made for organization only?

1 answer

3


Just organization, nothing changes in execution.

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

Others are not so radical, after all, it is rare to be a problem. Separation can occur by other factors, including separation of responsibilities within the team. A common one is when a guy is very big and makes sense big guys, unlike what some preach.

What should be avoided is to simulate classical inheritance, trait or things like that with partial. Even that I would say just to avoid, not not never to do.

Browser other questions tagged

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