Data clump

Uses your system voice; voice and rate in settings.

Snapshot

≈ 4 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In object-oriented programming, a data clump is any group of variables which are passed around together (in a clump) throughout various parts of the program. A data clump, like other code smells, can indicate deeper problems with the program design or implementation. The group of variables that typically make up a data clump are often closely related or interdependent and are often used together in a group as a result. A data clump is also known as a specific kind of class-level code smell that may be a symptom of poorly written source code.

In object-oriented programming, a data clump is any group of variables which are passed around together (in a clump) throughout various parts of the program. A data clump, like other code smells, can indicate deeper problems with the program design or implementation. The group of variables that typically make up a data clump are often closely related or interdependent and are often used together in a group as a result. A data clump is also known as a specific kind of class-level code smell that may be a symptom of poorly written source code. public void AddCoords(int x, int y, int z) { // ... } Post refactor: public void AddCoords(Coords coords) { // ... } public class Coords { public Coords(int x, int y, int z) { this.X = x; this.Y = y; this.Z = z; } public int X { get; } public int Y { get; } public int Z { get; } } package org.wikipedia.examples; public class Example { public static void welcomeNew(String firstName, String lastName, int age, String gender, String occupation, String city) { System.out.printf("Welcome %s %s, a %d-year-old %s from %s who works as a %s.%n", firstName, lastName, age, gender, city, occupation); } public static void main(String args[]) { String firstName = args[0]; String lastName = args[1]; int age = Integer.parseInt(args[2]); String gender = args[3]; String occupation = args[4]; String city = args[5]; welcomeNew(firstName, lastName, age, gender, occupation, city); } } In the previous example, all of the variables could be encapsulated into a single " Person " object, which could be passed around by itself. Additionally, the programmer may then recognize that the welcomeNew method would be better associated with the Person class, and could then come up with other relevant actions associated with the Person . For instance, the code could be refactored and expanded as follows: package org.wikipedia.examples; public class Example { public record Person(String firstName, String lastName, int age, String gender, String occupation, String city) { // Custom methods can be added to records, so let's include the welcomeNew() and work() methods. public void welcomeNew() { System.out.printf("Welcome %s %s, a %d-year-old %s from %s who works as a %s.%n", firstName, lastName, age, gender, city, occupation); } public void work() { System.out.printf("This is %s working hard on %s in %s%n", firstName, occupation, city); } } public static void main(String args[]) { String firstName = args[0]; String lastName = args[1]; int age = Integer.parseInt(args[2]); String gender = args[3]; String occupation = args[4]; String city = args[5]; Person joe = new Person(firstName, lastName, age, gender, occupation, city); joe.welcomeNew(); joe.work(); } } Although this has increased the length of the code, now the single Person can easily be passed around as one object, rather than as a variety of (seemingly unrelated) fields. Additionally, this gives the opportunity to move associated methods into the class so that they can easily operate upon individual instances thereof. These methods no longer require passing around a tedious list of parameters, as they are instead stored as instance variables upon the object instances themselves.

Text derived from https://en.wikipedia.org/w/index.php?oldid=1364398042 under CC BY-SA 4.0; modifications have been made.

Provenance

snapshot enwiki-001364398042 · captured 1784181092.0 · version history

Cite this page as: encyclopegia.org, “Data clump”, snapshot enwiki-001364398042. https://encyclopegia.org/a/data-clump

Sources cited in this revision

No external citation was extracted for this revision. That is a statement about the source, not a claim that none exists.