Is defining get/set methods for every field overkill?


Sat Nov 19 22:57:36 UTC 2022


On Thursday, 17 November 2022 at 04:39:35 UTC, thebluepandabear 
wrote:
> ...
> I am debating whether or not I should add getter methods to 
> these properties. On one hand, it will inflate the codebase by 
> a lot, on the other hand -- in other languages like Java it is 
> a good practice:
>

You really should, instead, be debating why your class has public 
member variables.

If you come to the conclusion that those member variables are 
completely ok being public, then making them private and thus 
needing to provide a simple getter/setter for getting/setting the 
raw value, well, that is just equivalent to making them public 
anyway, really.

So have you achieved nothing with that refactoring?

Well, only time (and 100's of users) will tell ;-)

Do I really need a fence around my house... well.. only time will 
tell.

I'm inclined to build the fence anyway.

Though it would be great if didn't need fences.


More information about the Digitalmars-d-learn mailing list