paint-brush
What is Primitive Obsession and How Can we Fix it?by@samwalpole
14,012 reads
14,012 reads

What is Primitive Obsession and How Can we Fix it?

by Sam Walpole7mMarch 26th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow
EN

Too Long; Didn't Read

Primitive Obsession is a code smell in which primitive data types are used excessively to represent your data models. Primitives are the basic data types available in most languages. For example, a string could represent a name, an address, or even an ID. The problem with primitives is they are very general. They can't contain any model-specific logic or behaviour, meaning that any logic must be stored in the containing class. This means you end up with classes containing lots of unrelated logic, which violates the Single Responsibility Principle.

Company Mentioned

Mention Thumbnail
featured image - What is Primitive Obsession and How Can we Fix it?
Sam Walpole HackerNoon profile picture
Sam Walpole

Sam Walpole

@samwalpole

Fullstack .NET and JavaScript web developer. Coding teacher and advocate

About @samwalpole
LEARN MORE ABOUT @SAMWALPOLE'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Sam Walpole HackerNoon profile picture
Sam Walpole@samwalpole
Fullstack .NET and JavaScript web developer. Coding teacher and advocate

TOPICS

Languages

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite