Based on experience only, I say that using methods, a method to get the value, and another to set the value, is a waste of unnecessary code unless you have rules (validations / checks) to be made on the value that will be obtained or set to field .
In Delphi , the default code used is, for example:
TPessoa = class
private
FNome: string;
public
property Nome: string read FNome write FNome;
end;
// e usa-se assim
pessoa := TPessoa.Create;
pessoa.Nome := 'Fulano';
Where there is a Nome
property that directly accesses field FNome
(in Delphi ) field and not attribute ).
The same could be written as follows:
TPessoa = class
private
FNome: string;
private SetNome(AValue: string);
function GetNome: string;
public
property Nome: string read GetNome write SetNome;
end;
...
private TPessoa.SetNome(AValue: string);
begin
// possíveis verificações e validações ...
FNome := AValue;
end;
procedure TPessoa.GetNome: string;
begin
// possíveis verificações e validações ...
result := FNome;
end;
Here it is used in the same way:
pessoa := TPessoa.Create;
pessoa.Nome := 'Fulano';
In this way, you use the GetNome
method when trying to retrieve the property value and SetNome
to set the value.
This is where you probably wondered about the need to use property
with Get and Set methods and you probably wondered why not just use the SetXXX and GetXXX methods methods, as in the example?
TPessoa = class
private
FNome: string;
public
private SetNome(AValue: string);
function GetNome: string;
end;
The default with property
is a custom that comes from time.
For C # , over time it was allowed to write properties with anonymous methods:
public class Pessoa
{
public string Nome { get; set; }
}
// e você usa assim:
var pessoa = new Pessoa();
pessoa.Nome = 'Fulano';
And the main issue of your taste is most likely your custom with Java .
If I'm not mistaken, using Java 8 Well, especially if I'm not mistaken, it leads me to the conclusion that this method has been considered more and more practical than accessing values from fields only by in Get and Set .
Finally, as I said that I was only relying on my own experience, what coding standard to use is not an obligation but rather an optional one, so it's up to you whether the Delphi application will only be serviced by you or if it goes for others with experience only in Delphi. If you still want to just use the Getters and Setters methods
The difference in use between one form and another I believe is just the extra effort for the class user to access a field methods rather than directly by the property.
About the advantages and disadvantages: I believe there are only advantages to using the coding standards of each language, because it makes it more intelligible by another programmer who comes by hand in its source code.
I believe that everyone who programs in one language and then needs to program in another tends to want to use the same coding pattern in both.