Untitled conversation
- User
from abc import ABC, abstractmethod from dataclasses import dataclass, replace from datetime import datetime, timezone from enum import Enum, auto # --- ドメイン例外 --- class DomainError(Exception): pass class TitleLengthError(DomainError): pass # --- Clock インターフェース --- class Clock(ABC): @abstractmethod def now(self) -> datetime: ... # --- Value Object for Title --- @dataclass(frozen=True) class Title: value: str def __post_init__(self): if not (1 <= len(self.value) <= 100): raise TitleLengthError("title must be 1-100 chars") # --- ステータス列挙 --- class Status(Enum): INCOMPLETE = auto() DONE = auto() # --- Task Entity --- @dataclass(frozen=True) class Task: id: int title: Title status: Status created_at: datetime def toggle(self) -> "Task": ns = Status.DONE if self.status == Status.INCOMPLETE else Status.INCOMPLETE return replace(self, status=ns) @property def done(self) -> bool: return self.status == Status.DONE # --- Factory for Task Creation --- class TaskFactory: def __init__(self, clock: Clock): self._clock = clock def create(self, id: int, title_str: str) -> Task: title = Title(title_str) return Task( id=id, title=title, status=Status.INCOMPLETE, created_at=self._clock.now() )
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.