---
# (DD18) Business Logic — Owner.toString() [11 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `org.springframework.samples.petclinic.owner.Owner` |
| Layer | Utility / Domain Model |
| Module | `owner` (Package: `org.springframework.samples.petclinic.owner`) |

## 1. Role

### Owner.toString()

This method produces the canonical text representation of an `Owner` domain object for diagnostics, logging, debugging, and display-adjacent use cases. It does not change persistent state or derive new business data; instead, it assembles a stable snapshot of the owner's identity and contact information into a readable string.

The method follows a formatter/decorator pattern by delegating the rendering work to Spring's `ToStringCreator`, which incrementally appends the object's fields and then finalizes the string. The output includes the entity identity (`id`), lifecycle status (`new`), customer name (`lastName`, `firstName`), and contact fields (`address`, `city`, `telephone`). Because the method reads both inherited and local fields, it acts as a shared view helper for the domain model and supports consistent representation across screens, logs, and test assertions.

There are no conditional branches, loops, or alternate service paths. The entire method is a single linear formatting flow that reads the current object's state and returns the assembled result.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
START(["toString()"])
A["Create ToStringCreator with current Owner instance"]
B["Append id from getId()"]
C["Append new state from isNew()"]
D["Append lastName from getLastName()"]
E["Append firstName from getFirstName()"]
F["Append address field"]
G["Append city field"]
H["Append telephone field"]
I["Build final string with ToStringCreator.toString()"]
END_NODE(["Return string representation"])
START --> A
A --> B
B --> C
C --> D
D --> E
E --> F
F --> G
G --> H
H --> I
I --> END_NODE
```

**CRITICAL — Constant Resolution:**
No business constants are referenced in this method. The method uses literal field labels supplied directly to `ToStringCreator`.

## 3. Parameter Analysis

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

This method takes no parameters. It operates on the current `Owner` instance and reads the following instance state: inherited identity and lifecycle status from `BaseEntity`, plus the owner profile fields `lastName`, `firstName`, `address`, `city`, and `telephone`.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `BaseEntity.getId` | BaseEntity | - | Calls `getId` in `BaseEntity` |
| - | `BaseEntity.isNew` | BaseEntity | - | Calls `isNew` in `BaseEntity` |
| R | `Person.getFirstName` | Person | - | Calls `getFirstName` in `Person` |
| R | `Person.getLastName` | Person | - | Calls `getLastName` in `Person` |

Analyze all method calls within this method and classify each as a CRUD operation.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `BaseEntity.getId` | BaseEntity | - | Reads the persistent identifier from the inherited base entity state |
| R | `BaseEntity.isNew` | BaseEntity | - | Reads the lifecycle flag that indicates whether the owner has been persisted before |
| R | `Person.getLastName` | Person | - | Reads the owner's family name for inclusion in the formatted string |
| R | `Person.getFirstName` | Person | - | Reads the owner's given name for inclusion in the formatted string |
| R | `Owner.address` field access | Owner | - | Reads the owner's street address for inclusion in the formatted string |
| R | `Owner.city` field access | Owner | - | Reads the owner's city for inclusion in the formatted string |
| R | `Owner.telephone` field access | Owner | - | Reads the owner's telephone number for inclusion in the formatted string |
| C | `ToStringCreator.append` | Spring utility | - | Incrementally composes the formatted output string |
| R | `ToStringCreator.toString` | Spring utility | - | Finalizes and returns the composed string representation |

## 5. Dependency Trace

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 | `NamedEntity` | `NamedEntity.toString` -> `Owner.toString` | `BaseEntity.getId [R]` |
| 2 | `Owner` | `Owner.toString` | `ToStringCreator.toString [R]` |
| 3 | `Test / utility code` | `Caller.toString` -> `Owner.toString` | `Owner.address [R]` |
| 4 | `Test / utility code` | `Caller.toString` -> `Owner.toString` | `Owner.city [R]` |
| 5 | `Test / utility code` | `Caller.toString` -> `Owner.toString` | `Owner.telephone [R]` |

The method is a terminal formatter with no downstream business-service invocation. In this codebase, the most direct callers are object-rendering paths and test code that invoke `toString()` for assertions, logging, or debugging output.

## 6. Per-Branch Detail Blocks

There are no conditional branches, loops, or switch statements in this method.

**Block 1** — [SEQUENTIAL] `(method entry and string assembly)` (L148-L157)

> Builds a readable string by appending the owner's identity, lifecycle state, name, and contact details in a fixed order.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `new ToStringCreator(this)` |
| 2 | CALL | `append("id", this.getId())` |
| 3 | CALL | `append("new", this.isNew())` |
| 4 | CALL | `append("lastName", this.getLastName())` |
| 5 | CALL | `append("firstName", this.getFirstName())` |
| 6 | SET | `append("address", this.address)` |
| 7 | SET | `append("city", this.city)` |
| 8 | SET | `append("telephone", this.telephone)` |
| 9 | CALL | `.toString()` |
| 10 | RETURN | `return ...;` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `Owner` | Domain entity | Pet owner record in the Petclinic system, representing a customer who registers pets and their contact details |
| `id` | Field | Unique persistent identifier for the owner record |
| `new` | Field / lifecycle flag | Indicates whether the owner has not yet been persisted and is still in a transient state |
| `lastName` | Field | Owner family name used for identification and sorting |
| `firstName` | Field | Owner given name used for identification |
| `address` | Field | Owner street address for correspondence and contact |
| `city` | Field | Owner city for contact and location reference |
| `telephone` | Field | Owner telephone number for direct contact |
| `BaseEntity` | Technical term | Shared superclass that provides common entity behavior such as identifier handling and new/existing state |
| `ToStringCreator` | Technical term | Spring utility that builds a structured string representation of an object |
| `toString()` | Technical term | Java object-rendering method used to provide a human-readable representation of a domain object |
| Petclinic | Product term | Sample veterinary clinic application used as the business context for the domain model |
| Domain model | Technical term | Object model representing business entities and their attributes without UI or transport concerns |

