Code Smell 141 - IEngine , AVehicle, ImplCar

Photo by Tim Mossholder on Unsplash

Code Smell 141 - IEngine , AVehicle, ImplCar

Have you ever seen an IEngine in the wild?

Maxi Contieri
·Jun 18, 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
  • Exceptions
  • Tags
  • Conclusion
  • Relations
  • More Info
  • Credits

TL;DR: Don't prefix or suffix your classes

Problems

  • Readability

  • Bijection Fault

  • Implementative Names

Solutions

  1. Remove prefixes and suffixes

  2. Name your objects after what they do

Context

Some languages have cultural conventions related to data types, Abstract classes, or Interfaces.

These names load our models with cognitive translations hard to follow.

We must KISS.

Sample Code

Wrong

public interface IEngine
{
    void Start();
}

public class ACar 
{

}

public class ImplCar 
{

}

public class CarImpl
{

}

Right

public interface Engine
{
    void Start();
}

public class Vehicle 
{

}

public class Car 
{

}

Detection

[X] Automatic

If we have a Thesaurus we can point to awkward names.

Exceptions

In C# it's a common practice to put "I" in the name of an interface because without it, you can't tell whether it is an interface or a class. This is a language smell.

Tags

  • Naming

Conclusion

Use real names for your models.

Relations

More Info

Credits

Photo by Tim Mossholder on Unsplash


Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.

Jamie Zawinski


This article is part of the CodeSmell Series.

 
Share this

Impressum

Technical Opinions are my own. I don't have the revealed truth.

Software Design is a creative activity. These are hints and not rigid rules.

I write on BackEnd Business Systems and OOP Design. My advice/experience might not suit other systems.

You can write me at info(at)maximilianocontieri.com