17
Code Smell 92 - Isolated Subclasses Names
If your classes are globals, use fully qualified names
TL;DR: Don't use abbreviations in subclasses
Readability
Mistakes
Rename your classes to provide context
Use modules, namespaces or fully qualified names
abstract class PerserveranceDirection {
}
class North extends PerserveranceDirection {}
class East extends PerserveranceDirection {}
class West extends PerserveranceDirection {}
class South extends PerserveranceDirection {}
//Subclasses have short names and meaningless outside the hierarchy
//If we reference East we might mistake it for the Cardinal Point
abstract class PerserveranceDirection {
}
class PerserveranceDirectionNorth extends PerserveranceDirection {}
class PerserveranceDirectionEast extends PerserveranceDirection {}
class PerserveranceDirectionWest extends PerserveranceDirection {}
class PerserveranceDirectionSouth extends PerserveranceDirection {}
//Subclasses have fully quallified names
Automatic detection is not an easy task. We could enforce local naming policies for subclasses.
- Naming
Choose your names wisely.
If your language supports it, use modules, namespaces and local scopes.
Photo by Edvard Alexander Rølvaag on Unsplash
The programmer's primary weapon in the never-ending battle against slow system is to change the intramodular structure. Our first response should be to reorganize the modules' data structures.
Frederick P. Brooks
This article is part of the CodeSmell Series.
17