Skip to Content
Clean Code Cookbook
book

Clean Code Cookbook

by Maximiliano Contieri
September 2023
Intermediate to advanced
430 pages
8h 6m
English
O'Reilly Media, Inc.
Book available
Content preview from Clean Code Cookbook

Chapter 4. Primitive Obsession

The obsession with primitives is a primitive obsession.

Rich Hickey

4.0 Introduction

Many software engineers think that software is about “moving data around”; object-oriented schools and textbooks focus on the data and attributes when teaching about modeling the real world. This was a cultural bias taught in universities during the ’80s and ’90s. Industry trends pushed engineers to create entity-relationship diagrams (ERDs) and reason about the business data instead of focusing on the behavior.

Data is more relevant than ever. Data science is growing and the world revolves around data. You need to create a simulator to manage and protect data and expose behavior while hiding information and accidental representation to avoid coupling. The recipes from this chapter will help you identify small objects and hide accidental representation. You will discover many cohesive small objects and reuse them in many different contexts.

Cohesion

Cohesion is a measure of the degree to which the elements within a single software class or module work together to achieve a single, well-defined purpose. It refers to how closely related the objects are to each other and to the overall goal of the module. You can see high cohesion as a desirable property in software design since the elements within a module are closely related and work together effectively to achieve a specific goal.

4.1 Creating Small Objects

Problem

You have big objects containing only primitive ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

GitOps Cookbook

GitOps Cookbook

Natale Vinto, Alex Soto Bueno
Data-Oriented Programming

Data-Oriented Programming

Yehonathan Sharvit

Publisher Resources

ISBN: 9781098144715Errata PageSupplemental Content