B
B
BonBon Slick2019-10-08 13:37:36
Network administration
BonBon Slick, 2019-10-08 13:37:36

Public access + const modifier or private access + getter?

There is a parameter in the class, which approach is more common when it is necessary to give the opportunity to see the parameter without the possibility of changing it?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
Dmitry, 2018-07-01
@Ali9664

5-7 thousand is a zilch. I have 20,000 site views plus 40,000 - 60,000 mobile app requests. Copes Xeon E5620, even 30% is not loaded.
You and VPS will do, but you have the main load on the disk. Need a lot of space. There is never a lot of space on a VPS.
You may be advised time4vps, but there is extremely terrible performance, terrible oversell. So you need to separate: VPS + server for storing files.
And since the music, then the server must also be bulletproof.

S
Sergey Gornostaev, 2018-07-01
@sergey-gornostaev

5-7 thousand visitors a day say almost nothing. There is a big difference between the fact that each visitor simply downloads a static mp3 in ten seconds, or if each of them keeps a connection to the service for an hour, encoding both the media data and the rtsp stream for them on the fly. In the first case, you can start on the deshman virtual hosting itself, and in the second, VDS may not be enough.

M
m0nym, 2018-07-01
@m0nym

Start with VDS.
Their tariff plans (and their corresponding resources) are very easy to change. Sometimes only a reboot is required. Sometimes a reboot is not needed.
Start with the cheapest VDS. Raise your plan as needed.
Thus, you can surely get an answer - which server is enough for you.

E
Evgeny Shatunov, 2019-10-08
@BonBonSlick

In mathematics, there is the concept of an invariant .
This term has also passed into programming , having undergone only minor changes in its meaning.
Briefly, an invariant is some consistent state of an instance, the consistency of which is preserved during the lifetime of the instance.
The invariant of an object is guaranteed by the public interface of that object's type. Therefore, any public access to the state of an object must not violate the invariant.
The C++ Core Guidelines have some very good advice on this topic.
From all this it follows that you almost never need to specify the fields as public. If there is no invariant and there is no need to protect the field from external change, then you should design the type as a structure, public access in which is access by default. You need a class in order to explicitly designate an invariant of your type and thereby limit the set of possible states of its instances. The presence of the invariant excludes direct public access to the state of the instance, i.e. all fields that refer to the state of the instance must be marked as private ( protectedor private). And to work with the state of the instance, you need to form a public interface that ensures the preservation of the invariant. This is handled through public accessors.

M
Maxim Moseychuk, 2019-10-08
@fshp

These are not equivalent cases.
In the variant with a getter, the variable itself can be modified. And the getter will return a new value each time.
With const, your variable will not change at all.
getter is always preferred. The compiler is smart enough to inline the getter. But the getter will allow you to add to it, for example, logging for debugging.
Or calculate the value on the fly.
In this case, the clients of your class will remain unchanged.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question