# Person

## Purpose

`Person` appears to be the shared domain model for people in the Petclinic application. It provides the common `firstName` and `lastName` fields used by multiple higher-level entities, so those entities do not need to duplicate the same name properties and validation rules.

Because it is annotated as a JPA mapped superclass, it is meant to contribute persistent state to subclasses rather than be stored as its own standalone table row.

## Design

This class acts as a **mapped superclass / reusable data object** in the domain model.

A few design choices stand out:

- It is annotated with `@MappedSuperclass`, which means its fields are inherited by JPA entities that extend it.
- It extends `BaseEntity`, so it participates in the shared entity identity/infrastructure used across the model layer.
- It is deliberately minimal: only state and simple getters/setters, with validation annotations on the fields.

In practice, `Person` is a base class for several concrete domain types such as `Owner` and `Vet`.

## Key Methods

The class exposes four public accessor methods. They are simple, but important because they define the canonical API for the inherited name fields.

### `String getFirstName()`

Returns the current value of the `firstName` field.

- **Parameters:** none
- **Return value:** the stored first name, or `null` if it has not been set
- **Side effects:** none

This method appears to be the standard read path for the first-name property. Because subclasses inherit it, callers can treat `Person`-derived objects uniformly when reading a person's given name.

### `void setFirstName(String firstName)`

Assigns a new value to the `firstName` field.

- **Parameters:** `firstName` — the value to store
- **Return value:** none
- **Side effects:** mutates the object's in-memory state

The field is annotated with `@NotBlank`, so this setter can accept any `String`, but validation may reject blank values later in the persistence or bean-validation lifecycle. This makes the method simple, but not fully self-validating.

### `String getLastName()`

Returns the current value of the `lastName` field.

- **Parameters:** none
- **Return value:** the stored last name, or `null` if it has not been set
- **Side effects:** none

This is the corresponding read accessor for the family-name property. Like `getFirstName()`, it is inherited by all subclasses and forms part of the common naming contract.

### `void setLastName(String lastName)`

Assigns a new value to the `lastName` field.

- **Parameters:** `lastName` — the value to store
- **Return value:** none
- **Side effects:** mutates the object's in-memory state

As with `setFirstName(String)`, validation is not enforced inside the method body itself. The `@NotBlank` annotation expresses the invariant that the property should not be blank, but enforcement likely happens externally.

## Relationships

`Person` sits in the middle of the model hierarchy as a reusable superclass for name-bearing entities.

### Depends on

- **`BaseEntity`** — inherited base type that likely provides the common identifier and persistence behavior for model classes.
- JPA and validation annotations used on the class and its fields:
  - `@MappedSuperclass`
  - `@Column`
  - `@NotBlank`

### Used by

- **`Owner`** — extends `Person` to inherit first and last name fields.
- **`Vet`** — extends `Person` to inherit first and last name fields.

Given the inbound connection count, this class appears to be a central shared abstraction in the domain model.

### Relationship diagram

```mermaid
flowchart TD
PersonClass["Person"]
BaseEntityClass["BaseEntity"]
OwnerClass["Owner"]
VetClass["Vet"]
PersonClass --> BaseEntityClass
OwnerClass --> PersonClass
VetClass --> PersonClass
```

## Usage Example

Typical usage appears to be indirect: code works with a concrete subclass such as `Owner` or `Vet`, but relies on `Person` for the shared name fields.

Example pattern:

```java
Owner owner = new Owner();
owner.setFirstName("George");
owner.setLastName("Franklin");

String fullName = owner.getFirstName() + " " + owner.getLastName();
```

A persistence or service layer might also work with `Person`-derived instances generically, since the common name accessors are guaranteed by the superclass.

## Notes for Developers

- **Mutability:** `Person` is mutable. The setter methods directly update state.
- **Validation:** `firstName` and `lastName` are marked `@NotBlank`, so blank values are not meant to be persisted, but the setters themselves do not enforce that rule.
- **Inheritance model:** Because this is a mapped superclass, it is meant to be extended rather than instantiated as a standalone persistence entity.
- **Thread safety:** The class is not thread-safe. Do not share instances across threads without external synchronization.
- **State invariants:** The intended invariant appears to be that both name fields should contain meaningful, non-blank text for valid domain objects.
- **Reuse:** If you introduce another person-like domain type, extending `Person` is likely the intended way to reuse the name fields and validation rules.
