Is it necessary to use setters and getters in structures to maintain good practices or is it only necessary in classes?
Is it necessary to use setters and getters in structures to maintain good practices or is it only necessary in classes?
Not needed in either. And this business of good practice is a fallacy.
For example, in C ++ it is not common to use this kind of mechanism. There are those who use them, but in specific application types and they would usually look better in another language.
There's room to do this, but C ++ programmers are often above average and know that in many cases it's not necessary. They do not follow good practices, they understand everything as it works, and know the requirements properly, and do not follow cake recipe. Every time you do something because it's good practice, you're already doing it wrong, even if it works. If you do it because you correctly and completely understand that it is necessary in that context, there is a good chance of being right.
A structure and a class is essentially the same thing in C ++, you can even use it differently, but technically there is no difference other than the visibility pattern of the members.
C ++ is a more dogmatic language, it allows you to do everything, but expects you to only use what you really need.
I usually say, if you do not understand all the implications of using a mechanism, do not use it. The site is full of information on the subject in several languages. It works the same in all, the difference is only cultural and frequency that it is necessary.
Not needed in either, but by default, in% with% s, the attributes are public. This means that if you have a struct
and you want to access one of the attributes of one of its copies from the outside, you need to set the attribute to class
or create the accessor and modifier (getter and setter) for him.
Is it necessary to use setters and getters in structures to maintain good practices or is it only necessary in classes?
Not needed in either. And this business of good practice is a fallacy.
For example, in C ++ it is not common to use this kind of mechanism. There are those who use them, but in specific application types and they would usually look better in another language.
There's room to do this, but C ++ programmers are often above average and know that in many cases it's not necessary. They do not follow good practices, they understand everything as it works, and know the requirements properly, and do not follow cake recipe. Every time you do something because it's good practice, you're already doing it wrong, even if it works. If you do it because you correctly and completely understand that it is necessary in that context, there is a good chance of being right.
A structure and a class is essentially the same thing in C ++, you can even use it differently, but technically there is no difference other than the visibility pattern of the members.
C ++ is a more dogmatic language, it allows you to do everything, but expects you to only use what you really need.
I usually say, if you do not understand all the implications of using a mechanism, do not use it. The site is full of information on the subject in several languages. It works the same in all, the difference is only cultural and frequency that it is necessary.
Not needed in either, but by default, in% with% s, the attributes are public. This means that if you have a %code% and you want to access one of the attributes of one of its copies from the outside, you need to set the attribute to %code% or create the accessor and modifier (getter and setter) for him.