Skip to content

Latest commit

 

History

History
45 lines (35 loc) · 1.75 KB

02-abstraction.md

File metadata and controls

45 lines (35 loc) · 1.75 KB

Abstrakcja


Abstrakcja

  • Interfejs
    • Publiczna część klasy
      • Metody (Member functions)
      • Funkcje spoza klasy (Non-member functions)
      • Typy wewnętrzne (Member types)
      • Wewnętrzne pola (Member fields)
      • Parametry szablonowe (Template parameters)
      • Specjalizacje
    • Przykład: std::vector na cppreference.com
    • Część prywatna (implementacja) jest nieznana
  • Object Oriented Design (OOD)

Make interfaces easy to use correctly and hard to use incorrectly

-- Scott Meyers, Effective C++


Przykład złego interfejsu

// 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);

Jak można ulepszyć klasę Date? Napisz w komentarzu 🙂