# Nomenclatura Geral

### **Nomenclatura**

##### **Componentes**

<span style="font-weight: 400;">Os componentes possuem seus prefixos utilizando letras que remetem ao nome completo da classe do componente. </span><span style="font-weight: 400;">Componentes herdados dos componentes listados e sem conexão ao banco de dados devem possuir o mesmo prefixo do componente principal, com exceção dos componentes visuais com conexão ao banco de dados, que utilizam o prefixo “DB“ seguido do padrão identificado logo abaixo. Exemplo: DBED\_Nome é um componente da classe TDBEdit, responsável pela representação de um nome.</span>

<span style="font-weight: 400;">Seguem alguns exemplos de prefixos padrões utilizados:</span>

<table border="1" id="bkmrk-ed_%3A-tedit%3B%E2%A0-ts_%3A-tta" style="border-collapse: collapse; width: 53.7037%; height: 377px;"><tbody><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">ED\_: TEdit; </span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">TS\_: TTabSheet;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">PN\_: TPanel;</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">RB\_: TRadioButton;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">GB\_: TGroupBox;</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">OD\_: TOpenDialog;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">LB\_: TLabel;</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">SD\_: TSaveDialog;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">MM\_: TMemo;</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">Q\_: TQuery, TFDQuery;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">BT\_: TButton (Botões num geral);</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">DS\_: TDataSource;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">CK\_: TCheckBox;</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">CDS\_: TClientDataSet;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">CB\_: TComboBox;</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">DSP\_: TDataSetProvider;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">LT\_: TListBox;</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">T\_: TTable;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">RG\_: TRadioGroup;</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">FR\_: TFrxReport;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">PC\_: TPageControl;</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">FDS\_: TFrxDBDataSet;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">TB\_: TToolBar;</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">RV\_: TRvProject;</span></td></tr><tr style="height: 29px;"><td style="width: 27.1031%; height: 29px;"><span style="font-weight: 400;">GD\_: TGrid;</span></td><td style="width: 26.6006%; height: 29px;"><span style="font-weight: 400;">DSC\_: TRvDataSetConnection;</span></td></tr><tr><td style="width: 27.1031%;"><span style="font-weight: 400;">MI\_: TMenuItem;</span></td><td style="width: 26.6006%;"><span style="font-weight: 400;">SH\_: TShape</span></td></tr><tr><td style="width: 27.1031%;"><span style="font-weight: 400;">IM\_: TImage</span></td><td style="width: 26.6006%;"><span style="font-weight: 400;">TM\_: TTimer </span></td></tr></tbody></table>

<span style="font-weight: 400;">Exemplo de componentes visuais com conexão ao banco de dados:  
</span>

<table border="1" id="bkmrk-dbed_%3A-tdbedit%3B-dbgd" style="border-collapse: collapse; width: 39.5062%; height: 58px;"><tbody><tr style="height: 29px;"><td style="width: 19.5062%; height: 29px;"><span style="font-weight: 400;">DBED\_: TDBEdit;</span></td><td style="width: 20%; height: 29px;"><span style="font-weight: 400;">DBGD\_: TDBGrid;</span></td></tr><tr style="height: 29px;"><td style="width: 19.5062%; height: 29px;"><span style="font-weight: 400;">DBCK\_: TDBCheckBox;</span></td><td style="width: 20%; height: 29px;"><span style="font-weight: 400;">DBRG\_: TDRadioGroup;</span></td></tr></tbody></table>

##### **Variáveis**

O nome da variável deve descrever de maneira clara e sem abreviações a função da variável. Utilizar a notação PascalCase para o nome da variável.  
As variáveis podem ter ainda um prefixo para adicionar mais informações sobre sua origem.  
Para **variáveis locais** utiliza-se o prefixo **‘L’**, para **argumentos (Parâmetros) de métodos** utiliza-se o **'A’**. Para **atributos (Field)** de classes utiliza-se o **‘F’**.

```PASCAL
type
  TPessoa = class
    protected
      FNome: String; // Campo nome da classe Pessoa. Prefixo F
    public
      constructor Create(ANome: String); // Argumento do método. Prefixo A.
  end;
  
implementation

constructor TPessoa.Create(ANome: String);
var
  LNome: String; // Variável local. Prefixo L
begin

end;
```

##### **Constantes** 

Para nomes de constantes, o padrão utilizado é:

```PASCAL
const
  NOME_DA_CONSTANTE_1 = 0;
  NOME_DA_CONSTANTE_2 = False;
  NOME_DA_CONSTANTE_3 = ‘Teste’;
```

O tipo da constante é deduzido através do valor dessa constante no momento da declaração. Porém, é possível declarar explicitamente um tipo para as constantes, e em alguns casos, como o de arrays, é necessário que esse tipo seja declarado.

```PASCAL
const
  NOME_DA_CONSTANTE_4: Double = 10;
  NOME_DA_CONSTANTE_5: array [1..2] of String = (‘a’, ‘b’);
```

##### **Métodos** 

Assim como o nome das variáveis, o nome do método deve seguir o mesmo modelo, com nomes que descrevem a função do método, utilizando também a notação PascalCase.  
Ao editar um método, é importante manter sua função original, caso sua funcionalidade seja alterada, deve-se refatorar o seu nome para que permaneça fiel ao seu comportamento.

**Exemplo 1: Criar um método que faça a confirmação de um rotina de gravação. Sem retorno e sem argumentos.**

```PASCAL
procedure ConfirmarGravacao();
```

**Exemplo 2: Criar um método que faça o cálculo da área de um retângulo. Seu retorno será um inteiro, esse método terá ainda dois argumentos, altura e largura.**

```PASCAL
function CalcularArea(AAltura, ALargura: Integer): Integer;
```

##### **Units**

As units padrões utilizadas anteriormente para as entidades eram nomeadas acrescentando 1, 2, 3 ou 4. Para facilitar o entendimento na leitura do nome da unit, elas passam a ser utilizadas no singular, seguido do nome de sua funcionalidade. Por exemplo, a entidade “Empresa” passa a ser utilizada como:  
● Empresas1: Empresa.Manutencao;  
● Empresas2: Empresa.Cadastro;  
● Empresas3: Empresa.Pesquisa;  
● Empresas4: Empresa.DataModule;  
Para units que tenham outra função que não se enquadrem nessas descritas anteriormente, o padrão é utilizar o nome da entidade seguido da descrição de sua função.  
Exemplo: Empresa.Copiar.

##### **Classes**

O padrão Delphi para nome de classes aconselha que ela inicie com o prefixo T (*Type*). É aconselhável que o nome dessas classes sejam descritivos quanto à sua entidade, função e/ou tipo. Por exemplo, uma classe que define a entidade produtos poderia ter o nome *TProdutoModelo*, enquanto o formulário para importação desses produtos poderia ser *TProdutoImportacaoFormulario.*