Make code easier to understand and maintain.
When you create a data member public, other programmers who use your class will naturally use these public elements, rather than some member function that provides the same or the same information simply because it is simpler. You might even do it yourself. This is understandable - programmers are by nature lazy beasts .
, , - , , -, -. , , - . , - , .
. , , , :
class Gizmo
{
public:
std::string mSku;
};
, , , . , mSku - , - "12345".
, , . , Amazon, . , mSku, . skus: S:12345, Z:12345.
, , , mSku , , . . 1 - . , , , mSku. , , . .
, mSku, -, , . - :
class Sku
{
public:
std::string ProductNumber() const;
private:
std::string mSku;
};
mSku , . , ProductNumber() , 1 - .
, . class private, - . protected, public.
[ ] , ?
, , , private .