---
# (DD09) Business Logic — Book.toString() [5 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `model.Book` |
| Layer | Utility |
| Module | `model` (Package: `model`) |

## 1. Role

### Book.toString()

`Book.toString()` provides the canonical human-readable presentation of a book domain object for display, logging, and debugging purposes. It converts the internal book attributes into a single formatted summary string that includes the book identifier, title, author, ISBN, and the current availability state. The method does not perform business validation or persistence; instead, it acts as a presentation helper that standardizes how a book is rendered wherever the object is inspected.

From a business perspective, this method supports the library domain by giving staff and users a concise, readable snapshot of a catalog item. It distinguishes between two availability states: `Available` and `Borrowed`, which helps downstream screens or logs communicate whether the book can currently be loaned out. The implementation follows a simple formatting/presentation pattern rather than a routing or delegation pattern. Because it is a shared domain-level string formatter, it can be reused anywhere the system needs a consistent textual representation of a book.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START["toString()"]
    FORMAT["Build formatted book display string using id, title, author, isbn, and availability"]
    AVAIL{"available?"}
    STATUS1["Use \"Available\""]
    STATUS2["Use \"Borrowed\""]
    RETURN["Return formatted String"]
    START --> FORMAT
    FORMAT --> AVAIL
    AVAIL -->|true| STATUS1
    AVAIL -->|false| STATUS2
    STATUS1 --> RETURN
    STATUS2 --> RETURN
```

The method constructs a display string in one pass and then returns it. The only business decision is the availability branch, which maps the boolean state to the user-facing labels `Available` or `Borrowed`.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

The method does not accept parameters. It reads the following instance fields from the `Book` object: `id`, `title`, `author`, `isbn`, and `available`. These fields represent the book identity, catalog title, creator, international book identifier, and lending status.

## 4. CRUD Operations / Called Services

The method contains no service calls, repository calls, or CRUD operations. It only formats in-memory state from the current `Book` instance into a string.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | (none) | - | - | No external read/write/delete activity; this method is presentation-only. |

## 5. Dependency Trace

`Book.toString()` is a leaf-level formatting method and is not responsible for calling other business services. Based on the caller search, it is invoked by other domain model classes and service-layer code when they need a readable book representation.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `model.Member` | `model.Member.toString` -> `model.Book.toString` | `toString [R] Book display text` |
| 2 | `model.Loan` | `model.Loan.toString` -> `model.Book.toString` | `toString [R] Book display text` |
| 3 | `service.LibraryService` | `service.LibraryService` -> `model.Book.toString` | `toString [R] Book display text` |
| 4 | `service.LoanService` | `service.LoanService` -> `model.Book.toString` | `toString [R] Book display text` |

## 6. Per-Branch Detail Blocks

**Block 1** — [RETURN] `(line 28)`

> Formats the book’s core attributes into a display string and resolves the availability label.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return String.format("[%s] \"%s\" by %s (ISBN: %s) - %s", id, title, author, isbn, available ? "Available" : "Borrowed");` |

**Block 1.1** — [TERNARY] `(available ? ... : ...)` `(line 28)`

> Converts the internal lending flag into a business-friendly status label.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `available ? "Available" : "Borrowed"` |
| 2 | RETURN | `"Available"` when the book can be loaned |
| 3 | RETURN | `"Borrowed"` when the book is currently checked out |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `id` | Field | Unique book identifier used to distinguish one catalog record from another |
| `title` | Field | Book title shown to users and staff |
| `author` | Field | Book author name used in catalog display |
| `isbn` | Field | International Standard Book Number — external publication identifier for the book |
| `available` | Field | Lending status flag indicating whether the book is currently available for checkout |
| `Book` | Domain object | Core library catalog entity representing a single book record |
| `toString()` | Java method | Standard object rendering method that produces a human-readable description |
| `Available` | Business term | Status meaning the book can be borrowed |
| `Borrowed` | Business term | Status meaning the book is currently on loan |
| LibraryService | Service layer | Application service that manages library catalog and member operations |
| LoanService | Service layer | Application service that manages borrowing and return workflows |
| `String.format` | Technical API | Java formatting utility used to compose the display string |
