DEV Community

Cover image for Code Smell 147 - Too Many Methods

Code Smell 147 - Too Many Methods

Maxi Contieri on July 06, 2022

Util classes are great to gather protocol TL;DR: Don't add an accidental protocol to your classes Problems Readability Single Respo...
Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️
public class Printer {
  public void print() { }
}
Enter fullscreen mode Exit fullscreen mode

I know this is an example, and such a class would usually have more methods and some state, but with the example like that, it's the perfect example of something that shouldn't be a class, but a simple subroutine.

Collapse
 
mcsee profile image
Maxi Contieri

Hi

Objects have protocols and behavior

Subroutines don't.
This is another Code Smell called 'Helpers'

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Subroutines don't.

This sentence has more flaws than words and that's kind of impressive.

  1. The "behaviour" is literally a bunch of subroutines
  2. Having behaviour is literally what subroutines are about
  3. How do you think calling subroutines even works if there are no protocols...?
Thread Thread
 
mcsee profile image
Maxi Contieri

hi

1 - The behavior is on the real world objects. I could never have a real world metaphore for a subroutine.
2 - Having behavior is always related to real world objects
3 - I don't do structured programming. So I don't know about subroutines. I am fine with them in structured paradigm.

Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

 So I don't know about subroutines

So you don't use methods on your objects?

Thread Thread
 
mcsee profile image
Maxi Contieri

of course.

Methods are the way to implement the accidental 'how' and to perform the essential 'what'
An object is what it does.
And methods fullfill the object's contract

Collapse
 
mcsee profile image
Maxi Contieri

Changed! Thank you very much!