Search code examples
c#terminology

C# Why property's get and set methods both called accessor but not accessor and mutator?


I read that (in C#) getter method is called 'accessor' and setter method is called 'mutator' (for example: methods get_Name(){} and set_Name(){}). But when we talk about properties (for example: string Name {get; set;}) I read that we don't call get and set methods as 'accessor' and 'mutator', but I read that we have to call get property as 'accessor' and set property as 'accessor'.

That is, I understand that I need to say property have two 'accessors' (get and set) and it's incorrectly to say that property have 'accessor' (get) and 'mutator' (set). Why?

I fully understand how methods and properties work. I have no problems with code. I just want to understand the terminology.


Solution

  • Why are you assuming that "accessor" means "get"? Accessor is just a generic term that provides some kind of access to the property. That could be read access ("getter"), write access ("setter"), or something else. Events also have accessors (add and remove, although more are possible).

    Accessors is simply shorter than "methods for interacting with the member", and more generic than "getters and setters". Maybe "getters and setters" is the thing you're looking for here.

    Ultimately, though, for reasons: the concept needed a name to simplify and formalize usage, and that was the word that was chosen.