Namespaces
Variants
Actions

Difference between revisions of "intro/encapsulation"

From cppreference.com
(Small grammar fix.)
(Typo error)
Line 2: Line 2:
 
The ability to hide the details from the user of your code and encapsulate everything under a clear interface is a great advantage.<br>
 
The ability to hide the details from the user of your code and encapsulate everything under a clear interface is a great advantage.<br>
 
example:<br>
 
example:<br>
  class sqaure{
+
  class square{
 
  public:
 
  public:
 
   rectangle( int top_left, int top_right, int buttom_left, buttom_right )
 
   rectangle( int top_left, int top_right, int buttom_left, buttom_right )

Revision as of 15:41, 12 January 2014

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.