Code Smell 174 - Class Name in Attributes

Photo by Phoenix Han on Unsplash

Code Smell 174 - Class Name in Attributes

Redundancy in names is a bad smell. Names should be contextual

Maxi Contieri
·Oct 29, 2022·

2 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Table of contents

  • Problems
  • Solutions
  • Context
  • Sample Code
  • Detection
  • Tags
  • Conclusion
  • Relations
  • More Info
  • Disclaimer
  • Credits

TL;DR: Don't prefix your attributes with your class name


  • Not Contextual Names


  1. Remove the class prefix from the attribute


This is a naming smell, we should not read attributes in isolation and names are contextual.

Sample Code


public class Employee {
   String empName = "John";
   int empId = 5;
   int empAge = 32;


public class Employee {
   String name;
   int id; // Ids are another smell
   int age; // Storing the age is yet another smell


[X] Semi-Automatic

When the full name is included in the prefix, our linters can warn us.


  • Naming


Careful naming is a very important task.

We need to name after the behavior, not type or data


More Info


Code Smells are just my opinion.


Photo by Phoenix Han on Unsplash

Copying skips understanding. Understanding is how you grow. You have to understand why something works or why something is how it is. When you copy it, you miss that. You just repurpose the last layer instead of understanding all the layers underneath.

Jason Fried

This article is part of the CodeSmell Series.

Share this