# (DD05) Business Logic — ConsoleUI.listBooks() [5 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `ui.ConsoleUI` |
| Layer | Controller |
| Module | `ui` (Package: `ui`) |

## 1. Role

### ConsoleUI.listBooks()

`listBooks()` is the console-facing retrieval routine for the library application’s book catalog. It delegates to `libraryService` to obtain the full list of registered books, then decides whether the user should see an empty-state message or the rendered book records. In business terms, this method is the read-only screen action behind the “List Books” menu choice and serves as the presentation layer’s bridge to the underlying book inventory data.

The method implements a simple routing-and-display pattern: it requests a collection from the service layer, evaluates whether the result contains any book rows, and then branches into one of two UI outcomes. If no books exist, it prints a user-friendly “No books.” message; otherwise, it streams each `Book` object to standard output using the object’s `toString()` representation. The method does not transform book data or persist changes; its role is to orchestrate display logic for the console screen and keep the UI responsive to the current state of the catalog.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START["listBooks()"]
    CALL1["libraryService.listAllBooks()"]
    DEC1{ "books.isEmpty()?" }
    NOBOOKS["Print \"No books.\""]
    PRINT["books.forEach(System.out::println)"]
    END_NODE["Return / Next"]

    START --> CALL1
    CALL1 --> DEC1
    DEC1 -->|Yes| NOBOOKS
    DEC1 -->|No| PRINT
    NOBOOKS --> END_NODE
    PRINT --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method accepts no parameters. It operates entirely from the current `ConsoleUI` instance state, calling the injected `libraryService` to retrieve the book catalog and using the returned list to determine whether to show an empty-state message or display each book. |

Instance fields / external state read by the method:
- `libraryService`: service dependency used to fetch the current set of books.
- Standard output (`System.out`): used to present the result to the user.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `libraryService.listAllBooks()` | Not indicated in source | Book catalog collection returned by the service | Reads the current book list for display in the console UI. |

Notes:
- No create, update, or delete behavior is performed by this method.
- The method contains one service call and one collection iteration for presentation only; no DB table names or SC/CBS identifiers are exposed in the available source.

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

No screen/batch entry points found within 8 hops. Direct callers found: 2 methods.
Terminal operations from this method: -

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `ConsoleUI` (menu dispatch) | `ConsoleUI.run()` -> `ConsoleUI.listBooks()` | `libraryService.listAllBooks() [R] Book collection` |
| 2 | `ConsoleUI` (internal screen action) | `ConsoleUI` menu case 2 -> `ConsoleUI.listBooks()` | `libraryService.listAllBooks() [R] Book collection` |

## 6. Per-Branch Detail Blocks

**Block 1** — `CALL` `(listAllBooks retrieval)` (L64)

> Retrieves the current book catalog from the service layer for display.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `List<Book> books = libraryService.listAllBooks();` |

**Block 2** — `IF` `(books.isEmpty())` (L65)

> Determines whether the catalog contains any books and routes to the appropriate console output.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `books.isEmpty()` |
| 2 | EXEC | `System.out.println("No books.");` |
| 3 | RETURN | `return;` |

**Block 2.1** — `ELSE` `(books is not empty)` (L65)

> Displays every retrieved book record to the console.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `books.forEach(System.out::println);` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `ConsoleUI` | Class | Console user interface component that presents menu actions and output to the end user. |
| `listBooks` | Method | UI action that retrieves and displays the full list of books. |
| `libraryService` | Field | Service dependency responsible for accessing book data from the application layer. |
| `Book` | Domain object | Business entity representing a book record in the library catalog. |
| `listAllBooks` | Method | Service method that returns all available books for read-only display. |
| `System.out` | Technical component | Standard console output stream used to print messages and records. |
| `isEmpty()` | Method | Collection check that determines whether any book records were returned. |
| `forEach` | Method | Iteration operation used to render each book entry to the console. |
| `No books.` | UI message | Empty-state message shown when the catalog has no entries. |
| `stdout` | Technical term | Standard output channel used for console presentation. |