Skip to main content

Command Palette

Search for a command to run...

Code Smell 45 - Not Polymorphic

Published
2 min read
Code Smell 45 - Not Polymorphic
M

I’m a senior software engineer loving clean code, and declarative designs. S.O.L.I.D. and agile methodologies fan.

Methods should be interchangeable if they do the same.

Problems

  • Missed Polymorphism

  • Coupling

  • IFs / Type check Polluting.

  • Names coupled to types.

Solutions

  1. Rename methods after what they do.

  2. Favor polymorphism.

Sample Code

Wrong

Detection

This is a semantic mistake. We could add a warning for similar method names on Polymorphic classes.

Tags

  • Polymorphic

Conclusion

Naming is very important. We need to name after concepts and not after accidental types.

Relations

More info


If you have three pet dogs, give them names. If you have 10,000 head of cattle, don't bother. Nowadays, the idea of giving a name to every file on your computer is ridiculous.

David Gelernter



This article is part of the CodeSmell Series.

C

This is such an important one, and honestly, I got this wrong some times, you want to name something correctly, but forget you already in a class or whatnot.

Thanks for the write-up!

2

Code Smells

Part 1 of 50

In this series, we will see several symptoms and situations that make us doubt the quality of our developments. We will present possible solutions. Most are just clues. They are no hard rules.