---
title: "Data Class"
type: "code-smell"
slug: "data-class"
url: "http://localhost:3000/en/smells/data-class.md"
category: "Dispensables"
description: "A data class refers to a class that contains only fields and crude methods for accessing them (getters and setters). These are simply containers for data used by other classes. These classes don’t contain any additional functionality and can’t independently operate on the data that they own."
---
# Data Class

> A data class refers to a class that contains only fields and crude methods for accessing them (getters and setters). These are simply containers for data used by other classes. These classes don’t contain any additional functionality and can’t independently operate on the data that they own.

## Signs and Symptoms

A data class refers to a class that contains only fields and crude methods for accessing them (getters and setters). These are simply containers for data used by other classes. These classes don’t contain any additional functionality and can’t independently operate on the data that they own.

## Reasons for the Problem

It’s a normal thing when a newly created class contains only a few public fields (and maybe even a handful of getters/setters). But the true power of objects is that they can contain behavior types or operations on their data.

## Payoff

* Improves understanding and organization of code. Operations on particular data are now gathered in a single place, instead of haphazardly throughout the code.
* Helps you to spot duplication of client code.
## Relations

**Treated by**

- [Encapsulate Field](/en/encapsulate-field.md)
- [Encapsulate Collection](/en/encapsulate-collection.md)
- [Move Method](/en/move-method.md)
- [Extract Method](/en/extract-method.md)
- [Remove Setting Method](/en/remove-setting-method.md)
- [Hide Method](/en/hide-method.md)


## Detected by

- **pmd** `DataClass` — Data Class (PMD) (https://pmd.github.io/pmd/pmd_rules_java_design.html#dataclass)
