concept

Primitive Obsession

Primitive Obsession is a code smell in software development where primitive data types (e.g., integers, strings, booleans) are overused to represent domain concepts, instead of creating dedicated classes or objects. This leads to code that is less expressive, harder to maintain, and more prone to errors due to scattered validation logic and lack of encapsulation. It often indicates a missed opportunity to model domain concepts more explicitly.

Also known as: Primitive Obsession code smell, Primitive Obsession anti-pattern, Primitive overuse, Primitive addiction, Primitive type misuse
🧊Why learn Primitive Obsession?

Developers should learn about Primitive Obsession to improve code quality by replacing primitive types with value objects or domain-specific types, which enhances readability, reduces duplication, and enforces business rules. This is particularly useful in domains like finance (e.g., using a Money class instead of a float), user management (e.g., Email class instead of string), or any system where data validation and behavior are critical.

Compare Primitive Obsession

Learning Resources

Related Tools

Alternatives to Primitive Obsession