# (DD11) Business Logic — LibraryService.registerMember() [6 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `service.LibraryService` |
| Layer | Service |
| Module | `service` (Package: `service`) |

## 1. Role

### LibraryService.registerMember()

This method performs the core business operation of registering a new library member into the system. It accepts the member’s display name and email address, generates an internal member identifier, constructs a domain `Member` object, and persists that object through the repository layer. In business terms, it is the entry point for onboarding a new customer into the library membership ledger.

The method follows a straightforward delegation and creation pattern: it does not branch by service type, apply alternative registration rules, or perform validation logic in the visible implementation. Instead, it consistently creates one member record per invocation and returns the created domain object to the caller for confirmation or downstream use. This makes the method a shared service-level operation that can be invoked from both automated startup flows and interactive UI flows.

In the wider system, `registerMember()` acts as a reusable application service used by the console UI and by bootstrap code. Its role is to centralize member creation so that callers do not need to know how member IDs are generated or how persistence is performed. The method therefore serves as a thin orchestration layer between user input and the member repository.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["registerMember(name, email)"])
    CREATE_ID(["Generate member ID with prefix M + 6-char uppercase UUID fragment"])
    CREATE_MEMBER(["Create Member(id, name, email)"])
    ADD_MEMBER(["memberRepo.add(member)"])
    RETURN_NODE(["Return Member"])
    START --> CREATE_ID
    CREATE_ID --> CREATE_MEMBER
    CREATE_MEMBER --> ADD_MEMBER
    ADD_MEMBER --> RETURN_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `name` | `String` | The member’s registered display name. It becomes the name attribute of the newly created library member record and is carried into the persisted domain object without transformation in this method. |
| 2 | `email` | `String` | The member’s contact email address. It becomes the email attribute of the newly created member record and is stored together with the generated member ID for later communication or identification. |

Instance fields / external state read by the method:
- `memberRepo` — repository used to persist the newly created member.
- `UUID.randomUUID()` — external runtime source used to generate the unique ID fragment.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| C | `memberRepo.add` | - | `Member` | Creates and stores a new member record in the repository using the generated ID, name, and email. |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 3 methods.
Terminal operations from this method: `memberRepo.add` [C] `Member`

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 | Batch / startup: `Main` | `Main.main` -> `LibraryService.registerMember` | `memberRepo.add [C] Member` |
| 2 | Screen: `ConsoleUI` | `ConsoleUI.registerMember` -> `LibraryService.registerMember` | `memberRepo.add [C] Member` |
| 3 | Service: `LibraryService` | `LibraryService.registerMember` | `memberRepo.add [C] Member` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] `(registerMember(name, email))` (L26)

> Registers a new member by generating an internal identifier before persistence.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String id = "M" + UUID.randomUUID().toString().substring(0, 6).toUpperCase();` // Generate a member ID with prefix `M` and uppercase UUID fragment |
| 2 | SET | `Member member = new Member(id, name, email);` // Build the domain member object from caller input |
| 3 | CALL | `memberRepo.add(member);` // Persist the new member record |
| 4 | RETURN | `return member;` // Return the created member to the caller |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|---------------------|
| `memberRepo` | Component | Member repository — persistence gateway used to store and retrieve member records. |
| `Member` | Domain object | Library member entity containing the generated member ID, name, and email address. |
| `name` | Field | Member display name captured during registration. |
| `email` | Field | Member contact email address captured during registration. |
| `UUID` | Technical term | Universally Unique Identifier generator used here as the source of the unique member ID fragment. |
| `randomUUID()` | Technical method | Runtime UUID generator that produces a unique identifier value. |
| `substring(0, 6)` | Technical operation | Extracts the first six characters of the UUID string for the member ID fragment. |
| `toUpperCase()` | Technical operation | Converts the generated UUID fragment to uppercase for consistent ID formatting. |
| `M` | Prefix | Member ID prefix indicating the identifier belongs to a member record. |
| register | Business term | The onboarding action of creating a new library member account. |