Sikau

Advanced JavaScript · Day 10 · about 35 min

Project: Library system

Classes working together.

Model a real system

A community library lends books to members. You'll model it with classes: books that know whether they're out, members with a borrowing limit, and a library that ties it together — with private data and clear errors.

The design

  • Book(title) — isOut getter.
  • Library — keeps books in a private Map by title, and loans by member name.
  • lend(title, member) — throws if the book is missing, already out, or the member has 2 books.
  • giveBack(title) — returns the book.

The rest of this lesson

  • Designing with classesexplain
  • Errors that explain themselvesexplain
  • Inside lend()order
  • Noun or verb?match
  • Build the librarychallenge
  • Badge quizquiz
  • Unit 2 complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 27 lessons of Advanced JavaScript