Code Smell 131 - Zero Argument Constructor

Photo by Ade Adebowale on Unsplash

Code Smell 131 - Zero Argument Constructor

Objects created without arguments are often mutable and erratic

Maxi Contieri
·Apr 22, 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
  • Tags
  • Conclusion
  • Relations
  • More Info
  • Credits

TL;DR: Pass all your essential arguments when creating objects.



  1. Use one complete and single constructor.

  2. Avoid Setters and Getters


It is common usage using a zero-argument constructor and a bunch of setters to change it.

Beans is a well-known example of this code smell.

Sample Code


 public Person();

// Anemic and mutable


public Person(String name, int age){ = name;
     this.age = age;

// We 'pass' the essence to the object 
// So it does not mutate


[X] Automatic

We can check all constructors, but there are some false positives.

Stateless objects are a valid example.


  • Mutability


Empty constructors are mutability hints and accidental implementation issues.

We need to research usages to improve our solutions.


More Info


Photo by Ade Adebowale on Unsplash

Don't worry about design, if you listen to your code a good design will appear...Listen to the technical people. If they are complaining about the difficulty of making changes, then take such complaints seriously and give them time to fix things.

Martin Fowler

This article is part of the CodeSmell Series.

Share this