How to stop naming Java classes with the "Manager" suffix
Tags: java, oop
Published: 2019-09-25 19:22:00

---
title: How to stop naming Java classes with the "Manager" suffix
published: true
description: Java class names are despised. Let's change that.
tags: java, oop
cover_image: 
---

Everywhere you look in a Java application, there are classes named SomethingManager. The account cache has an AccountCacheManager. The application properties have an ApplicationPropertiesManager. The user transaction is completed by a UserTransactionManager.

You probably named a class this way at some point. 

Please go change it.

## What's wrong with "Manager?"

Manager is a meaningless suffix. Sure, you might argue that we need a thing to manage another thing, but what do you mean when you say that? You're giving code a manager? Is this a workplace? Do objects in your application need a boss?

![Lumbergh from Office Space](https://thepracticaldev.s3.amazonaws.com/i/til3q7ug0668pf7p15ah.gif)

## How to change it?

Whenever I see "Manager" in a class name it's almost always redundant. I saw a class that managed the life cycle of another component recently. It was predictably named with the "LifeCycleManager" suffix. For sure this is a case where we need to name the class _manager_, right? After all, it _manages_ the life cycle and that's what we actually say in the real world?

No! Wrong! 

This class had `initialize()` and `stop()` methods. Let's assume the class it "managed" was called `MyComponent.` It's actually clearer and more readable to just call the "manager" class, `MyComponentLifeCycle`. The code where it's "managed" becomes `MyComponentLifeCycle.initialize()` and `MyComponentLifeCycle.stop()`. I can initialize or stop the life cycle directly, and when I do, I say what I mean and I mean what I say. I don't ask a manager to do it, I just do it.

![Shia LeBouf just do it](https://thepracticaldev.s3.amazonaws.com/i/0axn3j2i5d12oh7yjtcj.gif)

This simple idea applies across most use cases where I've seen the `Manager` suffix on a class. Just now, I opened up a code base and found a `ConnectionManager` class. Some of the methods it exposes are `getConnection()`, `configure()`, and `close()`.  Setting aside the fact that this class probably could be refactored into some other object that makes more sense, all its really doing is holding a `javax.sql.DataSource` and providing some utility code around it, with the ultimate goal of providing a valid `java.sql.Connection` to the application.

Can't this class just be called `DbConnection` and change that `getConnection()` method (which returns a `java.sql.Connection` by the way) to just `get()` or maybe `asSqlConnection()`? Now instead of having a `ConnectionManager.getConnection()` (which is totally redundant too by the way) you instead have `DbConnection.get()`. Later you call `DbConnection.close()`. No need for a "manager."

## No Managers!

As you can see, clean code should have no managers. It's redundant and unnecessary. It tells you nothing about what the class actually does.

My goal is manager extinction. Who's with me?

![Protest](https://thepracticaldev.s3.amazonaws.com/i/2pkloolt2rlyvqf1mfhd.gif)