Step 1: Design the system
In this project you design and build a library management system: books, members, loans and rules (a member may borrow at most two books, a book can only be on loan to one person). You will model it with Java classes, hide storage behind an interface, enforce rules with exceptions, design the SQL database, port the core to C#, and put it together. Every Java example was compiled and run for real.
Design first. List the nouns (things) and verbs (actions). Nouns become classes: Book, Member. Verbs become methods: borrow, giveBack, search. Rules become checks that throw exceptions: a book already on loan, a member over the limit. Then decide who is responsible for what: a Book knows its own data; a LibraryService knows the rules; a BookRepository knows how books are stored. Separating these makes the system easy to change.
| Part | Responsibility |
|---|---|
Book, Member | hold data |
BookRepository (interface) | find and store books |
LibraryService | enforce the loan rules |
| Database | keep the data safe between runs |
public class Main {
public static void main(String[] args) {
String[] nouns = {"Book", "Member", "Loan"};
String[] verbs = {"borrow", "giveBack", "search", "add"};
for (String n : nouns) System.out.println("class " + n);
for (String v : verbs) System.out.println("method " + v + "()");
}
}class Book class Member class Loan method borrow() method giveBack() method search() method add()
Which design choice keeps the rules separate from how data is stored?
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.