Back to Catalog
Code Smells
Bloaters
Primitive Obsession
Using primitive types instead of small objects for simple tasks.
Intent & Description
'
🎯 Intent
Identify when primitive types (strings, numbers) are used to represent domain concepts that should be objects.
📋 Context
You’re passing around primitive types like strings for phone numbers, email addresses, or money. Validation and behavior related to these concepts is scattered throughout the codebase.
💡 Solution
Create small classes or objects to represent these domain concepts. Move validation and related behavior into these classes.'
Real-world Use Case
Use when primitives are used for domain concepts that have behavior or validation requirements.
Source
📌 TL;DR
Use objects instead of primitives for domain concepts. Centralizes validation and behavior.