# (DD04) Business Logic — ConsoleUI.borrowBook() [6 LOC]

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

## 1. Role

### ConsoleUI.borrowBook()

This method is the console-side entry point for the library lending workflow. It collects the two business identifiers required to initiate a borrowing transaction: the book identifier and the member identifier. After capturing those inputs, it immediately delegates the actual borrowing logic to `loanService.borrowBook(...)` and prints the returned business message to the console.

From a design perspective, this method implements a simple routing and delegation pattern. It does not perform validation, state mutation, or persistence itself; instead, it acts as a thin presentation-layer adapter between the interactive console and the lending service. In the broader system, it supports the user-facing borrow operation that is typically invoked from the main menu dispatch in `ConsoleUI` and forwards the request into the service layer where the lending rules are enforced.

Because the method contains no branching, it has a single processing path: read both inputs, call the lending service, and display the outcome. Any business failure or success message is produced by the downstream service, not by this UI method.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START["borrowBook()"]
    INPUT_BOOK["Read Book ID from console"]
    INPUT_MEMBER["Read Member ID from console"]
    CALL_SERVICE["loanService.borrowBook(bookId, memberId)"]
    PRINT_RESULT["System.out.println(result)"]
    END_NODE["Return / Next menu"]

    START --> INPUT_BOOK
    INPUT_BOOK --> INPUT_MEMBER
    INPUT_MEMBER --> CALL_SERVICE
    CALL_SERVICE --> PRINT_RESULT
    PRINT_RESULT --> END_NODE
```

## 3. Parameter Analysis

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

This method has no formal parameters. It reads external state from the console via `InputUtils.readLine("Book ID: ")` and `InputUtils.readLine("Member ID: ")`, then uses the injected `loanService` instance to execute the borrow workflow. The method also reads and writes to standard output through `System.out.println(...)`.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `loanService.borrowBook` | N/A | `Book`, `Member`, `Loan` (in-memory list) | Delegates the borrow transaction to the service layer, where book and member existence are checked and a new loan record is created in application memory. |

### Called method evidence

- `ConsoleUI.borrowBook()` calls `loanService.borrowBook(String bookId, String memberId)`.
- In `LoanService.borrowBook(...)`, the service reads a book by ID and a member by ID, verifies availability, marks the book as unavailable, generates a loan ID, and appends a new `Loan` to the internal loan list.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 method.
Terminal operations from this method: `loanService.borrowBook [R/C] Book, Member, Loan`

Trace who calls this method and what this method ultimately calls.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen: `ConsoleUI` main menu dispatch | `ConsoleUI` menu handler -> `borrowBook()` | `loanService.borrowBook [R/C] Book, Member, Loan` |

## 6. Per-Branch Detail Blocks

**Block 1** — SEQUENCE `(single linear path)` (L85–L90)

> This block performs the complete borrow-book UI handoff with no conditional branching.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `InputUtils.readLine("Book ID: ")` // captures the book identifier from the operator |
| 2 | EXEC | `InputUtils.readLine("Member ID: ")` // captures the borrowing member identifier |
| 3 | CALL | `loanService.borrowBook(InputUtils.readLine("Book ID: "), InputUtils.readLine("Member ID: "))` // delegates the lending request to the service layer |
| 4 | EXEC | `System.out.println(...)` // prints the service result to the console |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `borrowBook` | Method | Console entry point for initiating a book borrowing transaction. |
| `Book ID` | Field / Input | Business identifier used to locate the book requested for loan. |
| `Member ID` | Field / Input | Business identifier used to identify the borrower who is checking out the book. |
| `loanService` | Service dependency | Lending service component that applies borrow rules and creates the loan record. |
| `Book` | Domain entity | Library item that can be borrowed, tracked by availability status. |
| `Member` | Domain entity | Registered library customer eligible to borrow books. |
| `Loan` | Domain entity | Borrowing record that links a book to a member. |
| `available` | Field | Book availability flag indicating whether the item can be borrowed. |
| `UUID` | Technical term | Universally Unique Identifier used here to generate a unique loan reference. |
| `ConsoleUI` | UI class | Console presentation layer that gathers user input and displays outcomes. |
| `InputUtils` | Utility | Helper for reading a line of text from console input. |
| `System.out.println` | Technical operation | Standard output used to display the borrow result to the user. |
