Although it's a common practice, and a good starting point, to put data members in a private section and member functions in a public section, we can't assume all members follow this pattern. Instead, it's crucial to check the accessibility symbols at the left of each member and translate them appropriately: "+" translates to a public member and "-" to a private one. Public data are rare, but private "helper" functions are sometimes helpful. You can put all private members in one section and all public members in another. Alternatively, you can create multiple public and private sections, separating data and functions into different groups.
Unlike Java, the public
and private
keywords are not applied to the class or individual members. In C++, the keywords label sections of a class: every feature appearing after a label exhibits the labeled accessibility until changed by another label. A class typically has two labeled sections but may have more if needed.
class ________ { private: feature1; feature2; public: feature3; feature4; };
UML class diagrams do not specify how a function performs its tasks (although other UML diagrams may). So, when we translate UML class diagrams into C++, the translation process only specifies the functions' prototype or signature and does not specify the contents of the functions' bodies.