Analyze the class provided in $ARGUMENTS for instances of primitive obsession and suggest value object extractions.
Instructions:
- •Examine the given class for primitive types that represent domain concepts
- •Identify groups of related primitives that could be encapsulated into value objects
- •Look for common patterns that indicate primitive obsession:
- •Multiple string/number parameters representing a single concept (e.g., street, city, state, zip for an address)
- •Validation logic scattered throughout the class for primitive values
- •Methods that operate on groups of related primitives
- •Repeated primitive type combinations across methods
- •Business rules applied to primitive values
Patterns to detect:
- •Money/Currency: Variables like price, cost, amount, fee, salary with currency
- •Email: String fields for email addresses lacking validation
- •Phone Numbers: Strings or numbers representing phone data
- •Addresses: Multiple fields like street, city, state, zipCode
- •Date Ranges: Separate startDate/endDate fields
- •Coordinates: Latitude/longitude pairs
- •Percentages: Numeric values representing percentages
- •Identifiers: Strings or numbers used as IDs
- •URLs: String representations of URLs
- •Names: Multiple fields like firstName, lastName, middleName
Output format:
- •List each identified primitive obsession case
- •Suggest a value object name and structure
- •Provide a brief implementation example with:
- •Constructor with validation
- •Relevant methods (equality, toString, etc.)
- •Any domain-specific behavior
- •Show how to refactor the original class to use the value object
- •Explain the benefits of each extraction
Focus on improving code expressiveness, encapsulation, and type safety while reducing duplication and scattering of domain logic.