An Interest In:
Web News this Week
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
- April 12, 2024
- April 11, 2024
Code Smell 174 - Class Name in Attributes
Redundancy in names is a bad smell. Names should be contextual
TL;DR: Don't prefix your attributes with your class name
Problems
- Not Contextual Names
Solutions
- Remove the class prefix from the attribute
Context
This is a naming smell, we should not read attributes in isolation and names are contextual.
Sample Code
Wrong
public class Employee { String empName = "John"; int empId = 5; int empAge = 32;}
Right
public class Employee { String name; int id; // Ids are another smell int age; // Storing the age is yet another smell}
Detection
[X] Semi-Automatic
When the full name is included in the prefix, our linters can warn us.
Tags
- Naming
Conclusion
Careful naming is a very important task.
We need to name after the behavior, not type or data
Relations
Code Smell 141 - IEngine , AVehicle, ImplCar
Maxi Contieri Jun 18 2 min read
More Info
What exactly is a name - Part II Rehab
Maxi Contieri May 23 '21 5 min read
Disclaimer
Code Smells are just my opinion.
Credits
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
Software Engineering Great Quotes
Maxi Contieri Dec 28 '20 13 min read
This article is part of the CodeSmell Series.
Original Link: https://dev.to/mcsee/code-smell-174-class-name-in-attributes-55c
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To