Mutable JavaBean-Klasse
Felder, Konstruktor, Getter, Setter, equals/hashCode und toString werden manuell gepflegt.
Vollständiger Legacy-Modern-Vergleich aller Java-Klassen, Tests, Maven-POMs und relevanten Ressourcen dieses Moduls. Jede Datei ist genau einmal einer fachlich passenden Vergleichsgruppe zugeordnet.
Felder, Konstruktor, Getter, Setter, equals/hashCode und toString werden manuell gepflegt.
Ein Record bildet unveränderliche Daten kompakt ab; der Status ist ein Enum statt freier Text.
Die Ähnlichkeit ist eine technische Orientierung auf normalisiertem Quelltext. Sie ersetzt keine fachliche Bewertung.
| Vergleichsgruppe | Legacy-Dateien | Modern-Dateien | Legacy-Zeilen | Modern-Zeilen | Ähnlichkeit |
|---|---|---|---|---|---|
| Build-Konfiguration | 1 | 1 | 34 | 34 | 100% |
| Bootstrap | 1 | 1 | 14 | 10 | 64% |
| Domänenmodell und Test | 2 | 3 | 54 | 36 | 9% |
Das Pair-POM bindet die Legacy- und Modern-Submodule zusammen und gehört deshalb ebenfalls zur vollständigen Codeabdeckung.
Java-/JUnit-Konfiguration wird verglichen.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| pom.xml | pom.xml | Direktvergleich Semantische Ähnlichkeit: 100% |
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>at.aydin.academy</groupId>
<artifactId>11javabasics-pair</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>java-basics-legacy</artifactId>
<packaging>jar</packaging>
<name>Java Basics Legacy</name>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>at.aydin.academy</groupId>
<artifactId>11javabasics-pair</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>java-basics-modern</artifactId>
<packaging>jar</packaging>
<name>Java Basics Modern</name>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>Startprogramme zeigen die Verwendung des Modells.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| BasicsLegacyApplication.java | BasicsModernApplication.java | Direktvergleich Semantische Ähnlichkeit: 64% |
package at.aydin.lab.basics.legacy;
public final class BasicsLegacyApplication {
private BasicsLegacyApplication() {
}
public static void main(String[] args) {
LegacyCustomer customer = new LegacyCustomer();
customer.setId(42L);
customer.setName("Aydin");
customer.setStatus("ACTIVE");
System.out.println(customer.displayText());
}
}package at.aydin.lab.basics.modern;
public final class BasicsModernApplication {
private BasicsModernApplication() {
}
public static void main(String[] args) {
System.out.println(new Customer(42, "Aydin", CustomerStatus.ACTIVE).displayText());
}
}Mutable Klasse wird mit Record/Enum-orientiertem Modell und Tests verglichen.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| LegacyCustomer.java LegacyCustomerTest.java | Customer.java CustomerStatus.java CustomerTest.java | Direktvergleich Semantische Ähnlichkeit: 9% |
package at.aydin.lab.basics.legacy;
// Design Pattern: JavaBean
// Zweck: Historische mutable Datenstruktur mit leerem Konstruktor und Settern.
public class LegacyCustomer {
private long id;
private String name;
private String status;
public LegacyCustomer() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String displayText() {
return id + ": " + name + " [" + status + "]";
}
}package at.aydin.lab.basics.legacy;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class LegacyCustomerTest {
@Test
void formatsMutableCustomer() {
LegacyCustomer c = new LegacyCustomer();
c.setId(1);
c.setName("Test");
c.setStatus("ACTIVE");
assertEquals("1: Test [ACTIVE]", c.displayText());
}
}package at.aydin.lab.basics.modern;
// Design Pattern: Value Object
// Zweck: Unveränderliche, validierte fachliche Daten mit wertbasierter Gleichheit.
public record Customer(long id, String name, CustomerStatus status) {
public Customer {
if (id <= 0) throw new IllegalArgumentException("id muss positiv sein");
if (name == null || name.isBlank()) throw new IllegalArgumentException("name fehlt");
if (status == null) throw new IllegalArgumentException("status fehlt");
}
public String displayText() {
return "%d: %s [%s]".formatted(id, name, status);
}
}package at.aydin.lab.basics.modern;
public enum CustomerStatus {
ACTIVE, INACTIVE
}package at.aydin.lab.basics.modern;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class CustomerTest {
@Test
void validatesAndFormatsRecord() {
assertEquals("1: Test [ACTIVE]", new Customer(1, "Test", CustomerStatus.ACTIVE).displayText());
}
@Test
void rejectsBlankName() {
assertThrows(IllegalArgumentException.class, () -> new Customer(1, "", CustomerStatus.ACTIVE));
}
}