Java · Intermediate level

Intermediate level · Module 6: Intermediate Java Project · Lesson 1 of 3

Designing the Library System

Turn the library requirements into packages, classes, interfaces and exceptions before writing code.

In this lesson you will

  • Produce a class and package design from requirements
  • Define a storage interface so persistence can change later

Key concepts

domain modelservice layerrepository interfacedesign review

The lesson

Start from the domain: Member, Book and Loan are model classes with no knowledge of files or menus. A LibraryService enforces the rules — loan limits, availability, due dates — and throws custom exceptions when a rule is broken.

Storage sits behind an interface such as LibraryRepository with methods like saveAll and loadAll. The first implementation uses CSV files; later you could replace it with a database without changing the service or the tests.

Review the design with a partner before coding: can each requirement be traced to a method? Is any class doing two jobs? Changes are cheap on paper and expensive in code.

Step by step

  1. List the requirements and the rules they imply.
  2. Draw the model classes and their fields.
  3. Write the LibraryService and LibraryRepository method signatures.
  4. Hold a ten-minute design review with a partner.

Practice activity

Submit a design document with packages, classes, interfaces, custom exceptions and the planned tests.

Expected result: An approved design where every requirement maps to a method and every rule to a test.

Check your understanding

  1. Why should model classes know nothing about files or menus?

    Show answer

    So they stay simple and reusable, and storage or interface changes do not affect them.

  2. What is the benefit of a repository interface?

    Show answer

    The storage method can be replaced, for example by a database, without changing the service code.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.