- Create Value[T] (frozen dataclass + ABC + Generic) in domain/framework/ - Migrate ClassifiedAdTitle and ClassifiedAdText to inherit Value[str] - Standardize all value access via .value instead of type-specific fields
46 lines
1.7 KiB
Markdown
46 lines
1.7 KiB
Markdown
# Plan: Value Object Base Class
|
|
|
|
## Goal
|
|
Create a generic `Value[T]` base class in the framework layer. All value objects standardize on `.value` access via inheritance.
|
|
|
|
## Design
|
|
|
|
### `Value[T]` base class (`domain/framework/value.py`)
|
|
```python
|
|
@dataclass(frozen=True)
|
|
class Value(ABC, Generic[T]):
|
|
value: T
|
|
```
|
|
|
|
- Frozen dataclass → immutability + structural equality (core Value Object semantics)
|
|
- `Generic[T]` → type-safe `.value` access in subclasses (e.g., `Value[str]`)
|
|
- `ABC` → mirrors the `Entity` pattern
|
|
|
|
### Subclasses
|
|
- `ClassifiedAdTitle(Value[str])` — drops `title: str`, inherits `value: T` bound to `str`
|
|
- `ClassifiedAdText(Value[str])` — drops `text: str`, inherits `value: T` bound to `str`
|
|
|
|
### Ripple effects
|
|
Every `.title` / `.text` reference on these objects becomes `.value`:
|
|
- `classified_ad.py` — `self.title.title` → `self.title.value`, construction calls, method bodies
|
|
- Tests — assertions, constructions, equality checks
|
|
|
|
## Files changed
|
|
| File | Change |
|
|
|------|--------|
|
|
| `domain/framework/value.py` | New — `Value[T]` base class |
|
|
| `domain/framework/__init__.py` | Add `Value` re-export |
|
|
| `domain/marketplace/classified_ad_title.py` | Inherit `Value[str]`, rename field |
|
|
| `domain/marketplace/classified_ad_text.py` | Inherit `Value[str]`, rename field |
|
|
| `domain/marketplace/classified_ad.py` | Update `.title`/`.text` refs → `.value` |
|
|
| `tests/test_classified_ad_title.py` | Update refs |
|
|
| `tests/test_classified_ad_text.py` | Update refs |
|
|
| `tests/test_classified_ad.py` | Update refs |
|
|
|
|
## Not in scope
|
|
`ClassifiedAdId`, `UserId`, `Money`, `Price` — stay as-is.
|
|
|
|
## Verification
|
|
- `pytest tests/` — all 63 tests pass
|
|
- `ruff check .` && `ruff format --check .` — clean
|