Re: Reason for Accessor Methods

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I think that you're confusing properties with fields. The OP was asking
for reasons why you would prefer to write this:

Thing someThing = myObject.GetSomething();

rather than this:

Thing someThing = myObject.Something;

where Something is a property with a getter (and perhaps a setter).

Certainly, it's preferable to expose properties rather than expose
fields directly. The question was, why would you prefer to write a Get
method rather than use a property with a getter.

.



Relevant Pages

  • Re: Reason for Accessor Methods
    ... >I think that you're confusing properties with fields. ... > for reasons why you would prefer to write this: ... > where Something is a property with a getter. ... it's preferable to expose properties rather than expose ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: naming conventions
    ... > Getter methods. ... > generality reasons, one can use getValue() that returns an Object, like Date ... calls the getters and does the validation, not the name of the getter. ...
    (comp.lang.java.programmer)