DEV Community

Cover image for Code Smell 177 - Missing Small Objects
Maxi Contieri ⭐⭐⭐
Maxi Contieri ⭐⭐⭐

Posted on • Originally published at maximilianocontieri.com

 

Code Smell 177 - Missing Small Objects

We see small primitive data everywhere

TL;DR: Don't forget to model the smallest ones

Problems

  • Primitive obsession

Solutions

  1. find responsibilities for small objects in the MAPPER

  2. Reify them

Context

Since computing early days we map all we see to the familiar primitive data types: Strings, Integers, Collections, etc.

Mapping to dates violates abstraction and fail-fast principles.

in the Wordle TDD Kata, we describe a Wordle word to be different than a String or Char(5), since they don't have the same responsibilities.

Sample Code

Wrong

public class Person {
    private final String name; 

    public Person(String name) {
        this.name = name;
    }
}
Enter fullscreen mode Exit fullscreen mode