Namespaces
Variants
Actions

encapsulation

From cppreference.com
Revision as of 09:00, 6 July 2020 by Cubbi (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Encapsulation is one of the most fundumental and valuable features of object oriented programming in general and c++ in particular. The ability to hide the details from the user of your code and encapsulate everything under a clear interface is a great advantage.
example:

class square{
public:
  rectangle( int top_left, int top_right, int buttom_left, buttom_right )
private:
  std::pair<int, int> top;
  std::pair<int, int> buttom;
};

In this example the interface calls for 4 integers and the implementation uses 2 pairs. The implementation along with the activities (not shown here) on the variables is encapsulated within the class.