Final Capstone: A Community Lending Library · capstone
Capstone project: Submit and Explain the Design
One file left, and it is the one a person actually runs.
main.py is where the library stops being a set of classes and becomes a program. Chapter 10 gave this file a specific job: know how to assemble the thing and how to talk to a person, and leave every rule to the
The entry file decides nothing
Read your main() when it is done and check that it contains no rules.
It should not work out whether an item is overdue, or how many loans a member may hold, or how to word a refusal. All three exist, and all three live somewhere else: on Loan, in checkout, and in the error classes from Lesson 8.
What is left for main is genuinely worth doing:
build a library and put things in it;
carry out a short scenario;
catch what comes back and say it in sentences;
print, which nothing else in the project is allowed to do.
That last one is the constraint Chapter 6 set: keep domain logic away from input and output. It survives here as a simple test. Search your other three files for print. There should not be any.
Catching the family
The scenario includes something being refused, because a program that only demonstrates the happy path is not demonstrating much:
try:
shelf.checkout("b1", "m2", 11)
except LibraryError as error:
print(f"Sam could not borrow it: {error}")
One except, and every refusal is covered. Lesson 8 built the message; main just puts it in a sentence. This is the payoff of a base class whose only job is to be catchable, and of errors that write their own messages: the entry file needs no idea which of the four it caught.
The explanation
The last thing to write is not code.
At the top of main.py, in the
Who owns what? Which object holds the catalog, the members, and the loans, and why they are in one place rather than three.
What did you derive rather than store? There are two obvious answers in this project. Say what would have gone wrong with the stored version.
Where would a new kind of item touch the code? Follow it through honestly, file by file.
Automated checks can verify that you replaced the placeholder with an explanation. A reviewer must judge whether it addresses all three topics and whether the reasoning is sound. The explanation is there because being able to say why a design is shaped the way it is, in plain sentences, is the difference between having followed eleven lessons and being able to do this again on a problem nobody has set for you.
Which of these belongs in main.py rather than further in?
What to build now
A build_library() that stocks the library, a main() that runs the scenario below and prints it, and the guard so importing the file runs nothing.
Then the explanation, and you are done.
Task
Finish main.py.
build_library() returns a library stocked with the book b1 (Solaris by Lem), the game g1 (Carcassonne, 5 players), and two members: m1 Mina with a limit of 3, and m2 Sam with a limit of 1.
main() runs this scenario on day 10 and prints exactly these five lines:
Community Lending Library
Available: Solaris by Lem, Carcassonne (up to 5 players)
Mina borrowed Solaris by Lem until day 31
Sam could not borrow it: item 'b1' is on loan until day 31
Overdue on day 32: b1
The available line joins the descriptions with ", ". Sam’s line comes from catching LibraryError and printing the error itself. The last line joins the overdue item ids the same way, for day 32.
End the file with the if __name__ == "__main__": guard, so importing it runs nothing.
Then write the