Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1.56 KB

File metadata and controls

42 lines (33 loc) · 1.56 KB

Abstraction


Abstraction

  • Interface
    • The public part of a class
      • Member function - obvious
      • Non-member function
      • Member types
      • Member fields
      • Template parameters
      • Specializations
    • Example: std::vector on cppreference.com
    • The private part (implementation) is unknown
  • Object Oriented Design (OOD)

Make interfaces easy to use correctly and hard to use incorrectly

-- Scott Meyers, Effective C++


Bad interface example

// A date class which is easy to use but also easy to use wrong.
class Date {
    public:
        Date(int month, int day, int year);
        ...
};

// Both are ok, but some european programmer may use it wrong,
// because european time format is dd/mm/yyyy instead of mm/dd/yyyy.
Date d(3, 4, 2000);
Date d(4, 3, 2000);