Is defining get/set methods for every field overkill?
thebluepandabear
therealbluepandabear at protonmail.com
Mon Nov 21 23:41:22 UTC 2022
On Monday, 21 November 2022 at 23:25:21 UTC, []() {}() wrote:
> On Monday, 21 November 2022 at 11:56:59 UTC, Ali Çehreli wrote:
>> ..
>> You took the question as whether to define them for class
>> hierarchies, safety-critical systems, etc.
>>
>> Ali
>
> Or even in a very, very simple counter class:
>
>
> public synchronized class Counter
> {
> static import core.atomic;
>
> private:
> int count = 0;
>
> public:
> void incrementCounter()
> {
> if ((count + 1) < 0)
> {
> // you might want to handle this
> }
> else
> core.atomic.atomicOp!"+="(this.count, 1);
> }
>
> int displayCounter()
> {
> return count;
> }
> }
But why give a C++ code example? 🤨
More information about the Digitalmars-d-learn
mailing list