Compare commits
15 Commits
3ae042e0bb
...
advancedSE
| Author | SHA1 | Date | |
|---|---|---|---|
| e4bc5347f1 | |||
| a360c4d986 | |||
| 9d393deaa7 | |||
| cf1bddd231 | |||
| f28603843d | |||
| 47c2ca7d36 | |||
| 52d6352334 | |||
| 68d7f3c3d9 | |||
| ce8a77d049 | |||
| 4f219ad5d5 | |||
| d56c7a1439 | |||
| 0e70985ff3 | |||
| 735990b7cf | |||
| 48928f8587 | |||
| ef3b0fce5f |
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -13,7 +13,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="19" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="19" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
28
combined.qmd
Normal file
28
combined.qmd
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
title: "Programmentwurf Advanced SoftwareEngineering"
|
||||||
|
subtitle: Für einen [PIC16f84-Simulator (Link)](https://git.paulmartin.cloud/paul/PIC-Simu/src/branch/advancedSE/)
|
||||||
|
abstract: Alle für die Vorlesung durchgeführten Änderungen befinden sich im Branch [advancedSE](https://git.paulmartin.cloud/paul/PIC-Simu/src/branch/advancedSE/). Als ursprünglicher Stand kann der [main-Branch](https://git.paulmartin.cloud/paul/PIC-Simu/src/branch/main/) oder [dieser Commit](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/c8f23176d25701c2de0723cd52bf2faaee121fb0) gesehen werden.
|
||||||
|
author:
|
||||||
|
- Luca Müller
|
||||||
|
- Paul Martin
|
||||||
|
date: 05/31/2025
|
||||||
|
date-format: "DD.MM.YYYY"
|
||||||
|
lang: de
|
||||||
|
format:
|
||||||
|
pdf:
|
||||||
|
toc: true
|
||||||
|
number-sections: true
|
||||||
|
colorlinks: true
|
||||||
|
crossref:
|
||||||
|
custom:
|
||||||
|
- kind: float
|
||||||
|
reference-prefix: UML-Diagramm
|
||||||
|
key: uml
|
||||||
|
latex-env: uml
|
||||||
|
latex-list-of-description: UML-Diagramme
|
||||||
|
---
|
||||||
|
|
||||||
|
\listof{uml}{Verzeichnis der UML-Diagramme}
|
||||||
|
|
||||||
|
{{< include paul.qmd >}}
|
||||||
|
{{< include luca.qmd >}}
|
||||||
511
luca.qmd
Normal file
511
luca.qmd
Normal file
@ -0,0 +1,511 @@
|
|||||||
|
---
|
||||||
|
lang: de
|
||||||
|
format:
|
||||||
|
pdf:
|
||||||
|
toc: true
|
||||||
|
number-sections: true
|
||||||
|
colorlinks: true
|
||||||
|
crossref:
|
||||||
|
custom:
|
||||||
|
- kind: float
|
||||||
|
reference-prefix: UML-Diagramm
|
||||||
|
key: uml
|
||||||
|
latex-env: uml
|
||||||
|
latex-list-of-description: UML-Diagramme
|
||||||
|
---
|
||||||
|
|
||||||
|
# Code Smell 1: Long Method
|
||||||
|
|
||||||
|
## Beschreibung des Problems
|
||||||
|
|
||||||
|
Das **Long Method** Anti-Pattern tritt auf, wenn eine einzelne Methode zu viele Zeilen Code enthält und multiple Verantwortlichkeiten übernimmt. Eine solche Methode verstößt gegen das **Single Responsibility Principle (SRP)** und führt zu verschiedenen Problemen:
|
||||||
|
|
||||||
|
- **Schwere Verständlichkeit**: Entwickler müssen viel Zeit aufwenden, um die gesamte Methode zu durchdringen
|
||||||
|
- **Reduzierte Testbarkeit**: Verschiedene Logikbereiche können nicht isoliert getestet werden
|
||||||
|
- **Mangelnde Wiederverwendbarkeit**: Teilfunktionalitäten sind nicht separat nutzbar
|
||||||
|
- **Erhöhte Fehleranfälligkeit**: Bugs sind schwerer zu lokalisieren und zu beheben
|
||||||
|
|
||||||
|
## Praktisches Beispiel
|
||||||
|
|
||||||
|
Die folgende Methode `stopRunFromBackend()` zeigt ein typisches Long Method Problem:
|
||||||
|
|
||||||
|
### Vorher (Problematischer Code)
|
||||||
|
|
||||||
|
```java
|
||||||
|
public static void stopRunFromBackend(String message){
|
||||||
|
// Zustandsänderungen
|
||||||
|
isAutoRunActive = false;
|
||||||
|
if (isSleeping)
|
||||||
|
wakeUpFromSleep();
|
||||||
|
else
|
||||||
|
DataRegister.resetPC();
|
||||||
|
|
||||||
|
// UI-Erstellung und -Konfiguration
|
||||||
|
Stage stoppedStage = new Stage();
|
||||||
|
stoppedStage.setTitle("Programm unterbrochen!");
|
||||||
|
VBox vbox = new VBox();
|
||||||
|
vbox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
Label grundlabel = new Label("Grund: " + message);
|
||||||
|
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
|
||||||
|
Label ueberlabel = new Label("Programm unterbrochen!");
|
||||||
|
vbox.getChildren().add(ueberlabel);
|
||||||
|
vbox.getChildren().add(grundlabel);
|
||||||
|
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
|
||||||
|
Scene scene = new Scene(vbox, 300, 90);
|
||||||
|
stoppedStage.setAlwaysOnTop(true);
|
||||||
|
stoppedStage.setScene(scene);
|
||||||
|
stoppedStage.show();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Identifizierte Probleme
|
||||||
|
|
||||||
|
- **Vermischte Verantwortlichkeiten**: Die Methode kombiniert Geschäftslogik (Zustandsänderungen) mit UI-Code
|
||||||
|
- **Schwere Testbarkeit**: UI-Code kann nicht isoliert von der Geschäftslogik getestet werden
|
||||||
|
- **Code-Duplikation**: Wird die Dialog-Funktionalität anderswo benötigt, muss der gesamte UI-Code kopiert werden
|
||||||
|
|
||||||
|
## Lösung: Extract Method Refactoring
|
||||||
|
|
||||||
|
Die **Extract Method** Technik löst das Problem durch Aufspaltung der langen Methode in kleinere, fokussierte Methoden:
|
||||||
|
|
||||||
|
### Nachher (Refactorierter Code)
|
||||||
|
|
||||||
|
```java
|
||||||
|
public static void stopRunFromBackend(String message){
|
||||||
|
handleExecutionStop();
|
||||||
|
showInterruptionDialog(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleExecutionStop(){
|
||||||
|
isAutoRunActive = false;
|
||||||
|
if (isSleeping)
|
||||||
|
wakeUpFromSleep();
|
||||||
|
else
|
||||||
|
DataRegister.resetPC();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void showInterruptionDialog(String message){
|
||||||
|
Stage stoppedStage = new Stage();
|
||||||
|
stoppedStage.setTitle("Programm unterbrochen!");
|
||||||
|
|
||||||
|
VBox vbox = new VBox();
|
||||||
|
vbox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
|
||||||
|
Label ueberlabel = new Label("Programm unterbrochen!");
|
||||||
|
Label grundlabel = new Label("Grund: " + message);
|
||||||
|
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
|
||||||
|
|
||||||
|
vbox.getChildren().addAll(ueberlabel, grundlabel);
|
||||||
|
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
|
||||||
|
|
||||||
|
Scene scene = new Scene(vbox, 300, 90);
|
||||||
|
stoppedStage.setAlwaysOnTop(true);
|
||||||
|
stoppedStage.setScene(scene);
|
||||||
|
stoppedStage.show();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Vorteile der Lösung
|
||||||
|
|
||||||
|
- **Klare Trennung der Verantwortlichkeiten**: Geschäftslogik und UI-Code sind getrennt
|
||||||
|
- **Verbesserte Lesbarkeit**: Jede Methode hat einen klaren, fokussierten Zweck
|
||||||
|
- **Erhöhte Wiederverwendbarkeit**: `showInterruptionDialog()` kann in anderen Kontexten genutzt werden
|
||||||
|
- **Bessere Testbarkeit**: Geschäftslogik und UI können separat getestet werden
|
||||||
|
|
||||||
|
|
||||||
|
# Code Smell 2: Large Class
|
||||||
|
|
||||||
|
## Beschreibung des Problems
|
||||||
|
|
||||||
|
Eine **Large Class** entsteht, wenn eine Klasse zu viele Verantwortlichkeiten übernimmt und dadurch überladen wird. Typische Kennzeichen sind:
|
||||||
|
|
||||||
|
- **Hohe Anzahl an Instanzvariablen**: Die Klasse verwaltet zu viele verschiedene Datentypen
|
||||||
|
- **Viele Methoden**: Unterschiedliche Funktionsbereiche werden in einer Klasse gemischt
|
||||||
|
- **Multiple Domänenaspekte**: Logik, Darstellung, Benutzerinteraktion und Statusverwaltung in einer Klasse
|
||||||
|
|
||||||
|
## Praktisches Beispiel
|
||||||
|
|
||||||
|
Die Klasse `Controller_Frontend` zeigt typische Large Class Probleme:
|
||||||
|
|
||||||
|
### Identifizierte Probleme
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class Controller_Frontend {
|
||||||
|
// GUI-Elemente
|
||||||
|
@FXML private Button startButton;
|
||||||
|
@FXML private Button pauseButton;
|
||||||
|
@FXML private Label statusLabel;
|
||||||
|
|
||||||
|
// Zustandsverwaltung (gehört nicht hierher!)
|
||||||
|
private static boolean isAutoRunActive = false;
|
||||||
|
private static boolean isSleeping = false;
|
||||||
|
private static double executionTimeMultiplier = 1.0;
|
||||||
|
|
||||||
|
// GUI-Steuerung
|
||||||
|
public void handleStart() { /* ... */ }
|
||||||
|
public void handlePause() { /* ... */ }
|
||||||
|
|
||||||
|
// Zustandslogik (gehört nicht hierher!)
|
||||||
|
public void sleep() { isSleeping = true; }
|
||||||
|
public void wakeUpFromSleep() { isSleeping = false; }
|
||||||
|
|
||||||
|
// ... viele weitere Methoden
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Auswirkungen
|
||||||
|
|
||||||
|
- **Schwere Wartbarkeit**: Änderungen in einem Bereich können unbeabsichtigte Nebeneffekte verursachen
|
||||||
|
- **Reduzierte Testbarkeit**: Verschiedene Aspekte können nicht isoliert getestet werden
|
||||||
|
- **Unübersichtlichkeit**: Die Klasse wird schnell unhandlich und schwer verständlich
|
||||||
|
- **Violierung des Single Responsibility Principle**: Eine Klasse sollte nur einen Grund zur Änderung haben
|
||||||
|
|
||||||
|
## Lösung: Extract Class Refactoring
|
||||||
|
|
||||||
|
Die Lösung besteht in der Auslagerung der Zustandsverwaltung in eine separate, spezialisierte Klasse:
|
||||||
|
|
||||||
|
### Neue ExecutionState Klasse
|
||||||
|
|
||||||
|
```java
|
||||||
|
/**
|
||||||
|
* Zentrale Verwaltung aller Ausführungszustände.
|
||||||
|
* Diese Klasse kapselt alle zustandsbezogenen Operationen
|
||||||
|
* und bietet eine saubere API für den Zugriff darauf.
|
||||||
|
*/
|
||||||
|
public class ExecutionState {
|
||||||
|
private static boolean isAutoRunActive = false;
|
||||||
|
private static boolean isSleeping = false;
|
||||||
|
private static double executionTimeMultiplier = 1.0;
|
||||||
|
|
||||||
|
// AutoRun-Zustand
|
||||||
|
public static boolean isAutoRunActive() {
|
||||||
|
return isAutoRunActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setAutoRunActive(boolean active) {
|
||||||
|
isAutoRunActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sleep-Zustand
|
||||||
|
public static boolean isSleeping() {
|
||||||
|
return isSleeping;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sleep() {
|
||||||
|
isSleeping = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void wakeUp() {
|
||||||
|
isSleeping = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ausführungsgeschwindigkeit
|
||||||
|
public static double getExecutionTimeMultiplier() {
|
||||||
|
return executionTimeMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setExecutionTimeMultiplier(double multiplier) {
|
||||||
|
if (multiplier > 0) {
|
||||||
|
executionTimeMultiplier = multiplier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hilfsmethoden
|
||||||
|
public static void reset() {
|
||||||
|
isAutoRunActive = false;
|
||||||
|
isSleeping = false;
|
||||||
|
executionTimeMultiplier = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Refactorierte Controller Klasse
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class Controller_Frontend {
|
||||||
|
// Nur noch GUI-Elemente
|
||||||
|
@FXML private Button startButton;
|
||||||
|
@FXML private Button pauseButton;
|
||||||
|
@FXML private Label statusLabel;
|
||||||
|
|
||||||
|
// Verwendung der ExecutionState Klasse
|
||||||
|
public void stopRunFromBackend(String message) {
|
||||||
|
ExecutionState.setAutoRunActive(false);
|
||||||
|
|
||||||
|
if (ExecutionState.isSleeping()) {
|
||||||
|
ExecutionState.wakeUp();
|
||||||
|
} else {
|
||||||
|
DataRegister.resetPC();
|
||||||
|
}
|
||||||
|
|
||||||
|
showInterruptionDialog(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Weitere GUI-Methoden...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Vorteile der Lösung
|
||||||
|
|
||||||
|
- **Klare Verantwortlichkeiten**: Controller fokussiert sich auf GUI, ExecutionState auf Zustandsverwaltung
|
||||||
|
- **Verbesserte Testbarkeit**: Zustandslogik kann isoliert getestet werden
|
||||||
|
- **Erhöhte Wiederverwendbarkeit**: ExecutionState kann in anderen Klassen genutzt werden
|
||||||
|
- **Bessere Wartbarkeit**: Änderungen an der Zustandslogik betreffen nur eine Klasse
|
||||||
|
|
||||||
|
|
||||||
|
# Code Smell 3: Shotgun Surgery
|
||||||
|
|
||||||
|
## Beschreibung des Problems
|
||||||
|
|
||||||
|
**Shotgun Surgery** tritt auf, wenn eine kleine fachliche Änderung Modifikationen an vielen verschiedenen Stellen im Code erfordert. Dieses Anti-Pattern entsteht durch:
|
||||||
|
|
||||||
|
- **Zu starke Verteilung**: Zusammengehörige Funktionalität ist über viele Klassen und Methoden verstreut
|
||||||
|
- **Mangelnde Kapselung**: Ähnliche Operationen sind nicht zentral gebündelt
|
||||||
|
- **Duplizierte Logik**: Gleiche oder ähnliche Code-Fragmente existieren an mehreren Stellen
|
||||||
|
|
||||||
|
## Praktisches Beispiel
|
||||||
|
|
||||||
|
Die Schlafmodus-Funktionalität war ursprünglich über mehrere Bereiche verteilt:
|
||||||
|
|
||||||
|
### Vor dem Refactoring (Problematische Verteilung)
|
||||||
|
|
||||||
|
```java
|
||||||
|
// In Controller_Frontend
|
||||||
|
private boolean isSleeping = false;
|
||||||
|
|
||||||
|
public void enterSleepMode() {
|
||||||
|
isSleeping = true;
|
||||||
|
// Logging hier
|
||||||
|
System.out.println("Entering sleep mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
// In ExecutionEngine
|
||||||
|
private boolean sleepState = false;
|
||||||
|
|
||||||
|
public void pauseExecution() {
|
||||||
|
sleepState = true;
|
||||||
|
// Ähnliches Logging dort
|
||||||
|
System.out.println("Execution paused - sleep mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
// In StatusManager
|
||||||
|
public void checkSleepStatus() {
|
||||||
|
if (someCondition) {
|
||||||
|
// Wieder ähnlicher Code
|
||||||
|
setSleeping(true);
|
||||||
|
System.out.println("Sleep mode activated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Identifizierte Probleme
|
||||||
|
|
||||||
|
- **Mehrfache Implementierung**: Sleep-Logik existiert in verschiedenen Varianten
|
||||||
|
- **Inkonsistente Zustände**: Verschiedene Klassen können unterschiedliche Sleep-Zustände haben
|
||||||
|
- **Hoher Änderungsaufwand**: Neue Sleep-Features müssen an mehreren Stellen implementiert werden
|
||||||
|
- **Fehleranfälligkeit**: Beim Hinzufügen neuer Funktionen können leicht Stellen vergessen werden
|
||||||
|
|
||||||
|
## Lösung: Zentralisierung durch Extract Class
|
||||||
|
|
||||||
|
Die Lösung besteht in der Konsolidierung aller sleep-bezogenen Operationen in der `ExecutionState` Klasse:
|
||||||
|
|
||||||
|
### Zentralisierte Lösung
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class ExecutionState {
|
||||||
|
private static boolean isSleeping = false;
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ExecutionState.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktiviert den Schlafmodus mit einheitlichem Logging und Zustandsmanagement
|
||||||
|
*/
|
||||||
|
public static void sleep() {
|
||||||
|
if (!isSleeping) {
|
||||||
|
isSleeping = true;
|
||||||
|
logger.info("Sleep mode activated");
|
||||||
|
notifyStateChange("SLEEP_ACTIVATED");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deaktiviert den Schlafmodus
|
||||||
|
*/
|
||||||
|
public static void wakeUp() {
|
||||||
|
if (isSleeping) {
|
||||||
|
isSleeping = false;
|
||||||
|
logger.info("Waking up from sleep mode");
|
||||||
|
notifyStateChange("SLEEP_DEACTIVATED");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Überprüft den aktuellen Schlafzustand
|
||||||
|
*/
|
||||||
|
public static boolean isSleeping() {
|
||||||
|
return isSleeping;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erweiterte Sleep-Funktionalität mit Timeout
|
||||||
|
*/
|
||||||
|
public static void sleepWithTimeout(long milliseconds) {
|
||||||
|
sleep();
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
wakeUp();
|
||||||
|
}
|
||||||
|
}, milliseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void notifyStateChange(String event) {
|
||||||
|
// Zentrale Benachrichtigung für alle interessierten Komponenten
|
||||||
|
EventBus.getInstance().publish(new StateChangeEvent(event));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Vereinfachte Nutzung in anderen Klassen
|
||||||
|
|
||||||
|
```java
|
||||||
|
// In Controller_Frontend
|
||||||
|
public void handleSleepButton() {
|
||||||
|
ExecutionState.sleep();
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
// In ExecutionEngine
|
||||||
|
public void pauseIfNeeded() {
|
||||||
|
if (shouldPause()) {
|
||||||
|
ExecutionState.sleep();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// In StatusManager
|
||||||
|
public void checkAndActivateSleep() {
|
||||||
|
if (criticalCondition()) {
|
||||||
|
ExecutionState.sleepWithTimeout(5000); // 5 Sekunden Sleep
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Vorteile der Lösung
|
||||||
|
|
||||||
|
- **Einheitliche Implementierung**: Alle sleep-bezogenen Operationen verwenden dieselbe Logik
|
||||||
|
- **Zentrale Wartung**: Änderungen müssen nur an einer Stelle vorgenommen werden
|
||||||
|
- **Konsistente Zustände**: Nur eine Quelle der Wahrheit für den Sleep-Zustand
|
||||||
|
- **Erweiterte Funktionalität**: Neue Features (wie Timeout) können zentral hinzugefügt werden
|
||||||
|
- **Bessere Nachverfolgbarkeit**: Einheitliches Logging und Event-System
|
||||||
|
|
||||||
|
# Anwendung von Programmierprinzipien im Projekt
|
||||||
|
|
||||||
|
## Einleitung
|
||||||
|
Im Rahmen der Refaktorisierung und Weiterentwicklung des Projekts wurde besonderer Fokus auf die Einhaltung zentraler Programmierprinzipien gelegt. Die folgenden Prinzipien wurden gezielt analysiert und angewendet:
|
||||||
|
|
||||||
|
## 1. SOLID-Prinzipien
|
||||||
|
|
||||||
|
### Single Responsibility Principle (SRP)
|
||||||
|
Die Methode `stopRunFromBackend()` wurde in zwei unabhängige Methoden aufgeteilt:
|
||||||
|
|
||||||
|
```java
|
||||||
|
public void stopRunFromBackend(String message) {
|
||||||
|
ExecutionState.setAutoRunActive(false);
|
||||||
|
handleSleepOrReset();
|
||||||
|
showStopDialog(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleSleepOrReset() {
|
||||||
|
if (ExecutionState.isSleeping()) {
|
||||||
|
ExecutionState.wakeUp();
|
||||||
|
} else {
|
||||||
|
dataRegister.resetPC();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void showStopDialog(String message) {
|
||||||
|
// GUI-Erzeugung...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Open/Closed Principle (OCP)
|
||||||
|
Die Klasse `ExecutionState` kapselt erweiterbare Zustandslogik, ohne dass bestehende Methoden geändert werden müssen:
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class ExecutionState {
|
||||||
|
private static boolean isAutoRunActive;
|
||||||
|
private static boolean isSleeping;
|
||||||
|
|
||||||
|
public static boolean isSleeping() { return isSleeping; }
|
||||||
|
public static void wakeUp() { isSleeping = false; }
|
||||||
|
public static void setAutoRunActive(boolean value) {
|
||||||
|
isAutoRunActive = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Liskov Substitution Principle (LSP)
|
||||||
|
`Controller_Frontend` implementiert ein Interface, wodurch die Substituierbarkeit gemäß LSP gewährleistet ist:
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class Controller_Frontend extends PICComponent
|
||||||
|
implements FrontendControllerInterface { }
|
||||||
|
|
||||||
|
public void resetPC() {
|
||||||
|
programCounter = 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Interface Segregation Principle (ISP)
|
||||||
|
Spezialisierte Interfaces sorgen dafür, dass Klassen nur relevante Funktionen implementieren:
|
||||||
|
|
||||||
|
```java
|
||||||
|
public interface TimerInterface {
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
int getCurrentTime();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Dependency Inversion Principle (DIP)
|
||||||
|
Zentrale Komponenten wie `PICComponentLocator` und Interfaces lösen die Abhängigkeit von konkreten Klassen:
|
||||||
|
|
||||||
|
```java
|
||||||
|
private PICComponentLocator picComponents;
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. GRASP-Prinzipien
|
||||||
|
|
||||||
|
### Low Coupling
|
||||||
|
Die Kopplung im Projekt ist durch Verwendung zentraler Zugriffsklassen wie `PICComponentLocator` gering gehalten.
|
||||||
|
|
||||||
|
```java
|
||||||
|
private PICComponentLocator picComponents;
|
||||||
|
```
|
||||||
|
|
||||||
|
### High Cohesion
|
||||||
|
Funktionen übernehmen jeweils thematisch zusammenhängende Aufgaben:
|
||||||
|
|
||||||
|
```java
|
||||||
|
public static void showStopDialog(String message) {
|
||||||
|
Stage stoppedStage = new Stage();
|
||||||
|
VBox vbox = new VBox();
|
||||||
|
Label grundlabel = new Label("Grund: " + message);
|
||||||
|
// GUI-Details ausgelassen
|
||||||
|
stoppedStage.show();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. DRY – Don’t Repeat Yourself
|
||||||
|
Wiederverwendbare Logik zur Statuskontrolle wurde in `ExecutionState` gekapselt. GUI-Erzeugung findet zentral in `showStopDialog()` statt:
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class ExecutionState {
|
||||||
|
private static boolean isSleeping;
|
||||||
|
public static boolean isSleeping() { return isSleeping; }
|
||||||
|
public static void wakeUp() { isSleeping = false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void showStopDialog(String message) {
|
||||||
|
// einmal zentral definierte GUI-Logik
|
||||||
|
}
|
||||||
317
paul.qmd
Normal file
317
paul.qmd
Normal file
@ -0,0 +1,317 @@
|
|||||||
|
---
|
||||||
|
lang: de
|
||||||
|
format:
|
||||||
|
pdf:
|
||||||
|
toc: true
|
||||||
|
number-sections: true
|
||||||
|
colorlinks: true
|
||||||
|
crossref:
|
||||||
|
custom:
|
||||||
|
- kind: float
|
||||||
|
reference-prefix: UML-Diagramm
|
||||||
|
key: uml
|
||||||
|
latex-env: uml
|
||||||
|
latex-list-of-description: UML-Diagramme
|
||||||
|
---
|
||||||
|
|
||||||
|
{{< pagebreak >}}
|
||||||
|
|
||||||
|
# Entwurfsmuster
|
||||||
|
Zusätzlich zu den beiden im Folgenden dargestellten Entwursmustern benutzen wir einen [Service Locator](https://en.wikipedia.org/wiki/Service_locator_pattern), der zu den [Architectural Patterns](https://en.wikipedia.org/wiki/Architectural_pattern) zählt. Dieses Pattern nutzt ein `HashMap`, in der verschiedene Komponenten des Programms gespeichert werden, um das Komponenten-Management zu vereinfachen und explizite Abhängigkeiten der Komponenten untereinander zu vermeiden, die das Initialisieren der einzelnen Komponenten erschweren könnten.
|
||||||
|
In unserem Projekt fungiert [`PICComponentLocator`](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/c38835fd7b47c662a344c9ab2c41e0527760bd61/src/main/java/fabrik/simulator/pic16f84/PICComponentLocator.java) als dieser Locator. Er besitzt einen `componentCatalogue` als Member, der eine `Map<Class<? extends PICComponentInterface>, PICComponentInterface>` ist. Das bedeutet, dass alle Klassen, die durch den Locator gemanaget werden sollen, das `PICComponentInterface` implementieren müssen.
|
||||||
|
|
||||||
|
Um nicht bei allen Zugriffen die `PICComponentLocator.getComponent()` ausführen zu müssen, wurde zusätzlich die `abstract` Klasse `PICComponent` [eingeführt]. Sie besitzt als Member alle implementierten Komponenten, also sollten neue Komponenten ebenfalls das Interface implementieren und als Member in `PICComponent` angelegt werden. Alle Komponenten können diese Klasse `extend`en und dadurch auch alle weiteren Komponenten als Member haben, dies ist auch in @uml-observer dargestellt [^1]. Durch die `initialize`-Funktion des `PICComponent` werden durch einen Aufruf der `PICComponentLocator.initAll()` alle Member vom Locator geholt.
|
||||||
|
|
||||||
|
## Marker-Entwurfsmuster
|
||||||
|
[Marker-Patterns](https://en.wikipedia.org/wiki/Marker_interface_pattern) werden allgemein genutzt, um Klassen Metadaten zuzuordnen. In unserem Projekt stellen die `FrontendSpecific`-Interfaces Marker dar, die genutzt werden um zu kommunizieren, dass Klassen andere Klassen benötigen, die Frontend-spezifisch sind und somit besonders beachtet werden müssen. So können alle [`Interface`s](LINK ZU ORDNER) definiert werden ohne direkt von fremdem Code abhängig zu sein. Bei möglichen anderen Frontend-Implementierungen müssten entsprechend nur die passenden Klassen die jeweiligen Interfaces implementieren und nichts an den Interfaces ändern.
|
||||||
|
Eingeführt wurden die `FrontendSpecific`s in [diesem Commit](https://git.paulmartin.cloud/paul/PIC-Simu/commit/06e934801645e32dea5415ccb4f38368a1667df6) ([hier](https://git.paulmartin.cloud/paul/PIC-Simu/commit/ef3b0fce5f9b6cce06494ff6ce59f5534064e7d2) verfollständigt). Es wurde zunächst ein `FrontendSpecificObject`-Interface angelegt, das alle Frontend-spezifischen Klassen beschreibt, die von Methoden anderer Klassen genutzt werden (sprich, die in den [`Interface`s](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/f28603843d7ef6cbf4666ab2b2ceda02ca411eb7/src/main/java/fabrik/simulator/pic16f84/interfaces) vorkommen). Es ist - entsprechend des Marker-Patterns - komplett leer [definiert](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/f28603843d7ef6cbf4666ab2b2ceda02ca411eb7/src/main/java/fabrik/simulator/pic16f84/frontendspecifics/FrontendSpecificObject.java):
|
||||||
|
```java
|
||||||
|
public interface FrontendSpecificObject {
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Zusätzlich gibt es für spezifische Frontend-Klassen auch `FrontendSpecific`-Interfaces, sodass nach wie vor nur bestimmte Klassen über- bzw. zurückgegeben werden können. Diese spezifischen Interfaces sind ebenfalls leer, nur nutzen sie `extends FrontendSpecificObject` um zu verdeutlichen, dass sie zu den allgemeinen `FrontendSpecificObject`s gehören. Hier beispielsweise [`FrontendSpecificCircle`](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/ef3b0fce5f9b6cce06494ff6ce59f5534064e7d2/src/main/java/fabrik/simulator/pic16f84/frontendspecifics/FrontendSpecificCircle.java):
|
||||||
|
```java
|
||||||
|
public interface FrontendSpecificCircle extends FrontendSpecificObject {
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Tatsächlich genutzt werden die `FrontendSpecific`-Interfaces von [Circle], [ToggleButtonGroup] und [Vbox]. Sie `extenden` ihr jeweiliges `JavaFX`-Pendant und `implementen` ihr jeweiliges `FrontendSpecific`-Interface. Darüber hinaus implementieren sie nur die nötigen (also im Code tatsächlich genutzten) Konstruktoren, die wiederum nur `super()` aufrufen, hier bspw. [`ToggleButtonGroup`]:
|
||||||
|
```java
|
||||||
|
public class ToggleButtonGroup extends
|
||||||
|
com.gluonhq.charm.glisten.control.ToggleButtonGroup
|
||||||
|
implements FrontendSpecificToggleButtonGroup {
|
||||||
|
public ToggleButtonGroup(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToggleButtonGroup(ToggleButton... toggles) {
|
||||||
|
super(toggles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Alle für das Marker-Pattern eingeführten Klassen sind in @uml-marker erkennbar [^1]:
|
||||||
|
|
||||||
|
::: {#uml-marker}
|
||||||
|
|
||||||
|
```{mermaid}
|
||||||
|
%%| fig-width: 6.5
|
||||||
|
classDiagram
|
||||||
|
direction TB
|
||||||
|
class FrontendSpecificObject {
|
||||||
|
<<Interface>>
|
||||||
|
}
|
||||||
|
class FrontendSpecificToggleButtonGroup {
|
||||||
|
<<Interface>>
|
||||||
|
}
|
||||||
|
class ToggleButtonGroup {
|
||||||
|
public ToggleButtonGroup()
|
||||||
|
public ToggleButtonGroup(ToggleButton... toggles)
|
||||||
|
}
|
||||||
|
|
||||||
|
class `com.gluonhq.charm.glisten.control.ToggleButtonGroup` {
|
||||||
|
...
|
||||||
|
....()
|
||||||
|
}
|
||||||
|
|
||||||
|
FrontendSpecificObject <|-- FrontendSpecificToggleButtonGroup : << extends >>
|
||||||
|
FrontendSpecificToggleButtonGroup <|-- ToggleButtonGroup : << implements >>
|
||||||
|
`com.gluonhq.charm.glisten.control.ToggleButtonGroup` <|-- ToggleButtonGroup : << extends >>
|
||||||
|
|
||||||
|
class FrontendSpecificVBox{
|
||||||
|
<<Interface>>
|
||||||
|
}
|
||||||
|
class VBox {
|
||||||
|
public VBox()
|
||||||
|
}
|
||||||
|
|
||||||
|
class `javafx.scene.layout.VBox` {
|
||||||
|
...
|
||||||
|
....()
|
||||||
|
}
|
||||||
|
|
||||||
|
FrontendSpecificObject <|-- FrontendSpecificVBox : << extends >>
|
||||||
|
FrontendSpecificVBox <|-- VBox : << implements >>
|
||||||
|
`javafx.scene.layout.VBox` <|-- VBox : << extends >>
|
||||||
|
|
||||||
|
class FrontendSpecificCircle {
|
||||||
|
<<Interface>>
|
||||||
|
}
|
||||||
|
class Circle {
|
||||||
|
public Circle()
|
||||||
|
}
|
||||||
|
|
||||||
|
class `javafx.scene.shape.Circle` {
|
||||||
|
...
|
||||||
|
....()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FrontendSpecificObject <|-- FrontendSpecificCircle : << extends >>
|
||||||
|
FrontendSpecificCircle <|-- Circle : << implements >>
|
||||||
|
`javafx.scene.shape.Circle` <|-- Circle : << extends >>
|
||||||
|
|
||||||
|
class PICComponentInterface{
|
||||||
|
<<Interface>>
|
||||||
|
+ initialize(PICComponentLocator picComponents)
|
||||||
|
}
|
||||||
|
|
||||||
|
class WindowManagement{
|
||||||
|
<<Interface>>
|
||||||
|
refreshTable()$
|
||||||
|
startFromMain(String[] args)$
|
||||||
|
}
|
||||||
|
|
||||||
|
FrontendSpecificObject <|-- WindowManagement : << extends >>
|
||||||
|
PICComponentInterface <|-- WindowManagement : << extends >>
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Das genutzte Marker-Pattern und alle seine Verwendungen.
|
||||||
|
:::
|
||||||
|
## Beobachter- (/Observer-) Entwurfsmuster
|
||||||
|
[Beobachter-Entwurfsmuster](https://en.wikipedia.org/wiki/Observer_pattern) werden genutzt, damit ein Subjekt mehrere Beobachter über eine Zustandsänderung informieren kann. In unserem Projekt passiert das bei einer Änderung der `totalExecutionTime`. Das Subjekt `ExecutionTimeSubject` führt hierbei ein `Set` an Beobachtern, die bei uns durch das Interface `ExecutionTimeObserver` repräsentiert werden, welches durch die `registerObserver`- und `unregisterObserver`-Funktionen verwaltet werden kann. Bei einer Zustandsänderung muss die `notifyObservers`-Funktion aufgerufen werden, welche für alle Observer die im Interface spezifizierte `executionTimeChanged`-Funktion aufruft. Die Implementierung wurde [hier](https://git.paulmartin.cloud/paul/PIC-Simu/commit/85bc6e9ebae4655ba3ad7ee360332010edc910dd) begonnen, [hier](https://git.paulmartin.cloud/paul/PIC-Simu/commit/cf6bcd8498cd2d03e85b0c5f6faaaed935d3a155) vereinfacht um das Threading des Frontends zu respektieren und [hier](https://git.paulmartin.cloud/paul/PIC-Simu/commit/52d63523341179c3c49e0ac31a60a8d7c11cdddc) in die letzten Tests eingefügt.
|
||||||
|
In der aktuellen Umsetzung übernimmt die [`Commands`](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/ef3b0fce5f9b6cce06494ff6ce59f5534064e7d2/src/main/java/fabrik/simulator/pic16f84/Commands.java)-Klasse gleichzeitig die Rolle des `ExecutionTimeSubject`s und `CommandsInterface`s. Deshalb [wird in der `Main`-Klasse](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/85bc6e9ebae4655ba3ad7ee360332010edc910dd/src/main/java/fabrik/simulator/pic16f84/Main.java) das `Commands`-Objekt dem `ComponentLocator` sowohl für die `ExecutionTimeSubject.class` als auch für die `CommandInterface.class` hinzugefügt. `ExecutionTimeObserver` sind die Klassen, die vorher `commands.getTotalExecutionTime()` gepollt haben. Die Implementierung dieses Entwursmusters ist in @uml-observer erkennbar [^1]:
|
||||||
|
|
||||||
|
:::{#uml-observer}
|
||||||
|
|
||||||
|
```{mermaid}
|
||||||
|
%%| fig-width: 6.5
|
||||||
|
classDiagram
|
||||||
|
direction TB
|
||||||
|
class PICComponentInterface{
|
||||||
|
<<Interface>>
|
||||||
|
+ initialize(PICComponentLocator picComponents)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CommandInterface {
|
||||||
|
<<Interface>>
|
||||||
|
+ CALL(int isr);
|
||||||
|
|
||||||
|
+ get_wRegister();
|
||||||
|
|
||||||
|
+ decode(int i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class PICComponent{
|
||||||
|
<<Abstract>>
|
||||||
|
# DataRegisterInterface dataRegister
|
||||||
|
...
|
||||||
|
|
||||||
|
+ initialize(PICComponentLocator locator)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ExecutionTimeSubject{
|
||||||
|
<<Abstract>>
|
||||||
|
- Set~ExecutionTimeObserver~ observers
|
||||||
|
|
||||||
|
+ registerObserver(ExecutionTimeObserver observer)
|
||||||
|
+ unregisterObserver(ExecutionTimeObserver observer)
|
||||||
|
+ getTotalExecutionTime()
|
||||||
|
+ addExecutionTime(int i)
|
||||||
|
+ getExecutionTimeMultiplier()
|
||||||
|
# notifyObservers()
|
||||||
|
....()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Commands{
|
||||||
|
- wRegister
|
||||||
|
- totalExecutionTime
|
||||||
|
- executionTimeMultiplier
|
||||||
|
....()
|
||||||
|
}
|
||||||
|
|
||||||
|
class FrontendSpecificObject {
|
||||||
|
<<Interface>>
|
||||||
|
}
|
||||||
|
|
||||||
|
class FrontendControllerInterface{
|
||||||
|
<<Interface>>
|
||||||
|
+ getPORTbuttons() FrontendSpecificToggleButtonGroup[]
|
||||||
|
+ getTRISbuttons() FrontendSpecificToggleButtonGroup[]
|
||||||
|
+ stopRunFromBackend(String watchdogTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Controller_Frontend {
|
||||||
|
...
|
||||||
|
....()
|
||||||
|
}
|
||||||
|
|
||||||
|
class TimerInterface {
|
||||||
|
<<Interface>>
|
||||||
|
+ cycles(int i)
|
||||||
|
+ incrementFromPin(int directRegister)
|
||||||
|
+ increment(boolean manual)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Timer {
|
||||||
|
...
|
||||||
|
....()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class EEPROMInterface {
|
||||||
|
<<Interface>>
|
||||||
|
registerTime(double executionTime, boolean b)
|
||||||
|
parse(int i, int content, int i1)
|
||||||
|
read(int address) long
|
||||||
|
write(int address, long data)
|
||||||
|
}
|
||||||
|
|
||||||
|
class EEPROM {
|
||||||
|
...
|
||||||
|
....()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ExecutionTimeObserver {
|
||||||
|
<<Interface>>
|
||||||
|
+ executionTimeChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
ExecutionTimeObserver <|-- Timer : << implements >>
|
||||||
|
TimerInterface <|-- Timer : << implements >>
|
||||||
|
PICComponent <|-- Timer : << extends >>
|
||||||
|
PICComponentInterface <|-- TimerInterface : << extends >>
|
||||||
|
PICComponentInterface <|-- EEPROMInterface : << extends >>
|
||||||
|
ExecutionTimeObserver <|-- EEPROM : << implements >>
|
||||||
|
EEPROMInterface <|-- EEPROM : << implements >>
|
||||||
|
PICComponent <|-- EEPROM : << extends >>
|
||||||
|
ExecutionTimeObserver <|-- Controller_Frontend : << implements >>
|
||||||
|
PICComponent <|-- Controller_Frontend : << extends >>
|
||||||
|
PICComponentInterface <|-- PICComponent : << implements >>
|
||||||
|
PICComponentInterface <|-- FrontendControllerInterface : << extends >>
|
||||||
|
FrontendControllerInterface <|-- Controller_Frontend : << implements >>
|
||||||
|
FrontendSpecificObject <|-- FrontendControllerInterface : << extends >>
|
||||||
|
CommandInterface <|-- Commands : << implements >>
|
||||||
|
ExecutionTimeSubject <|-- Commands : << extends >>
|
||||||
|
PICComponent <|-- ExecutionTimeSubject : << extends >>
|
||||||
|
PICComponentInterface <|-- CommandInterface : << extends >>
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Das genutzte Observer-Pattern und seine Verwendungen im (Nicht-Test-) Code.
|
||||||
|
:::
|
||||||
|
|
||||||
|
[^1]: Für das Pattern unwichtige Funktionen und Variablen wurden ausgelassen
|
||||||
|
|
||||||
|
|
||||||
|
# Clean Architecture
|
||||||
|
|
||||||
|
Die Clean Architecture ist darauf ausgelegt, Softwareprojekte langfristig betreibbar, flexibel und wartbar zu halten. Dazu wird das Projekt in **konzentrische Schichten** unterteilt, in denen die **Abhängigkeitsrichtung stets von außen nach innen** verläuft – die sogenannte *Dependency Rule*. Der Kern der Anwendung bleibt dabei vollständig unabhängig von technischen Details wie Benutzeroberflächen, Datenbanken oder Netzwerken.
|
||||||
|
|
||||||
|
In unserem Projekt haben wir diese Schichtarchitektur wie folgt umgesetzt:
|
||||||
|
|
||||||
|
## 1. Interface/Adapter-Schicht
|
||||||
|
|
||||||
|
Diese Schicht enthält alle Klassen, die als Schnittstelle zwischen der Anwendung und der Benutzeroberfläche dienen.
|
||||||
|
Dazu zählen alle Klassen im Package, `fabrik.simulator.pic16f84.frontendspecifics` insbesondere:
|
||||||
|
|
||||||
|
- `Controller_Frontend`
|
||||||
|
- `CreateWindow`
|
||||||
|
- `IOPorts`
|
||||||
|
- `ToggleButtonGroupExt`
|
||||||
|
|
||||||
|
Diese Klassen erben vom `FrontendSpecificObject` und sind spezifisch für die grafische Oberfläche. Sie implementieren die Schnittstellen der inneren Schichten und leiten Benutzerinteraktionen weiter.
|
||||||
|
|
||||||
|
## 2. Application Code
|
||||||
|
|
||||||
|
Die nächstinnere Schicht beinhaltet die anwendungsspezifische Logik – unsere *Use Cases*. Dazu zählen sämtliche Klassen im Package `fabrik.simulator.pic16f84`, **sofern sie nicht vom `FrontendSpecificObject` erben**. Diese Schicht ist weitgehend unabhängig von der GUI und bleibt stabil, selbst wenn sich die Darstellung oder Eingabeform ändert.
|
||||||
|
Diese Klassen gehören zur Anwendungslogik:
|
||||||
|
|
||||||
|
- `Timer`
|
||||||
|
- `PreScaler`
|
||||||
|
- `WatchdogTimer`
|
||||||
|
- `ProgrammStack`
|
||||||
|
|
||||||
|
## Main-Klasse als Plugin
|
||||||
|
|
||||||
|
Die `Main`-Klasse bildet den äußeren Rahmen (Plugin-Schicht) und initialisiert die gesamte Anwendung:
|
||||||
|
|
||||||
|
- Es werden alle Objekte erzeugt und dem `Locator` zugewiesen.
|
||||||
|
- Das `WindowManagement` startet das Frontend.
|
||||||
|
|
||||||
|
Ein besonders interessanter Aspekt: Wenn man sämtliche Referenzen auf das Frontend (z. B. in Zeile 19, 20, 23) entfernt, lässt sich die App **trotzdem erfolgreich starten und nutzen**. Das zeigt, dass die Schichten entkoppelt sind – ein zentrales Ziel der Clean Architecture.
|
||||||
|
|
||||||
|
\newpage
|
||||||
|
|
||||||
|
## Visualisierung
|
||||||
|
|
||||||
|
```{mermaid}
|
||||||
|
flowchart TB
|
||||||
|
subgraph Interface/Adapter-Schicht
|
||||||
|
A1[Controller_Frontend, CreateWindow, IOPorts, ToggleButtonGroupExt]
|
||||||
|
end
|
||||||
|
subgraph Application Code
|
||||||
|
A2[Use Cases, WatchdogTimer, PreScaler, ProgrammStack, Timer]
|
||||||
|
end
|
||||||
|
subgraph Plugin-Schicht
|
||||||
|
A3[Main.java]
|
||||||
|
end
|
||||||
|
|
||||||
|
A3 --> A1
|
||||||
|
A1 --> A2
|
||||||
|
```
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
|
|
||||||
|
import fabrik.simulator.pic16f84.frontendspecifics.Circle;
|
||||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
||||||
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
||||||
|
|
||||||
@ -14,7 +15,6 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.shape.Circle;
|
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|||||||
@ -4,9 +4,8 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import fabrik.simulator.pic16f84.interfaces.ExecutionTimeObserver;
|
import fabrik.simulator.pic16f84.interfaces.ExecutionTimeObserver;
|
||||||
import fabrik.simulator.pic16f84.interfaces.PICComponentInterface;
|
|
||||||
|
|
||||||
public abstract class ExecutionTimeSubject extends PICComponent implements PICComponentInterface{
|
public abstract class ExecutionTimeSubject extends PICComponent{
|
||||||
private Set<ExecutionTimeObserver> observers;
|
private Set<ExecutionTimeObserver> observers;
|
||||||
|
|
||||||
public ExecutionTimeSubject(){
|
public ExecutionTimeSubject(){
|
||||||
@ -24,8 +23,8 @@ public abstract class ExecutionTimeSubject extends PICComponent implements PICCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void notifyObservers(){
|
protected void notifyObservers(){
|
||||||
observers.forEach(o -> o.executionTimeChanged());
|
observers.forEach(o -> o.executionTimeChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTotalExecutionTime(){
|
public double getTotalExecutionTime(){
|
||||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
|
import fabrik.simulator.pic16f84.frontendspecifics.Circle;
|
||||||
|
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificCircle;
|
||||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
||||||
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
||||||
import fabrik.simulator.pic16f84.interfaces.*;
|
import fabrik.simulator.pic16f84.interfaces.*;
|
||||||
@ -8,7 +10,6 @@ import javafx.scene.control.ToggleButton;
|
|||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.paint.RadialGradient;
|
import javafx.scene.paint.RadialGradient;
|
||||||
import javafx.scene.paint.Stop;
|
import javafx.scene.paint.Stop;
|
||||||
import javafx.scene.shape.Circle;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -187,9 +188,9 @@ public class IOPorts extends PICComponent implements IOPortInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLEDs (Circle[] a, Circle[] b){
|
public void setLEDs (FrontendSpecificCircle[] a, FrontendSpecificCircle[] b){
|
||||||
allLEDsA = a;
|
allLEDsA = (Circle []) a;
|
||||||
allLEDsB = b;
|
allLEDsB = (Circle []) b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshTable(ToggleButtonGroup parent) {
|
public void refreshTable(ToggleButtonGroup parent) {
|
||||||
|
|||||||
@ -2,20 +2,20 @@ package fabrik.simulator.pic16f84;
|
|||||||
|
|
||||||
import fabrik.simulator.pic16f84.interfaces.*;
|
import fabrik.simulator.pic16f84.interfaces.*;
|
||||||
|
|
||||||
public abstract class PICComponent {
|
public abstract class PICComponent implements PICComponentInterface{
|
||||||
DataRegisterInterface dataRegister;
|
protected DataRegisterInterface dataRegister;
|
||||||
EEPROMInterface eeprom;
|
protected EEPROMInterface eeprom;
|
||||||
PreScalerInterface preScaler;
|
protected PreScalerInterface preScaler;
|
||||||
IOPortInterface ioPorts;
|
protected IOPortInterface ioPorts;
|
||||||
TimerInterface timer;
|
protected TimerInterface timer;
|
||||||
InterruptInterface interrupts;
|
protected InterruptInterface interrupts;
|
||||||
TableInterface table;
|
protected TableInterface table;
|
||||||
FrontendControllerInterface frontendController;
|
protected FrontendControllerInterface frontendController;
|
||||||
WatchdogTimerInterface watchdogTimer;
|
protected WatchdogTimerInterface watchdogTimer;
|
||||||
ProgramStackInterface programStack;
|
protected ProgramStackInterface programStack;
|
||||||
CommandInterface commands;
|
protected CommandInterface commands;
|
||||||
ExecutionTimeSubject executionTime;
|
protected ExecutionTimeSubject executionTime;
|
||||||
ToggleButtonInterface toggleButtonExt;
|
protected ToggleButtonInterface toggleButtonExt;
|
||||||
|
|
||||||
public void initialize(PICComponentLocator locator) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
toggleButtonExt = locator.getComponent(ToggleButtonInterface.class);
|
toggleButtonExt = locator.getComponent(ToggleButtonInterface.class);
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||||
|
|
||||||
|
|
||||||
|
public class Circle extends javafx.scene.shape.Circle implements FrontendSpecificCircle {
|
||||||
|
public Circle () {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||||
|
|
||||||
|
public interface FrontendSpecificCircle extends FrontendSpecificObject {
|
||||||
|
}
|
||||||
@ -6,7 +6,4 @@ public interface CommandInterface extends PICComponentInterface {
|
|||||||
int get_wRegister();
|
int get_wRegister();
|
||||||
|
|
||||||
void decode(int i);
|
void decode(int i);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
package fabrik.simulator.pic16f84.interfaces;
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
import javafx.scene.shape.Circle;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificCircle;
|
||||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
||||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ public interface IOPortInterface extends PICComponentInterface, FrontendSpecific
|
|||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
void setLEDs(Circle[] allLEDsA, Circle[] allLEDsB);
|
void setLEDs(FrontendSpecificCircle[] allLEDsA, FrontendSpecificCircle[] allLEDsB);
|
||||||
|
|
||||||
void setLEDs(boolean[] booleans);
|
void setLEDs(boolean[] booleans);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package fabrik.simulator.pic16f84.interfaces;
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificVBox;
|
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificVBox;
|
||||||
import javafx.scene.layout.VBox;
|
|
||||||
|
|
||||||
public interface TableInterface extends PICComponentInterface {
|
public interface TableInterface extends PICComponentInterface {
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package fabrik.simulator.pic16f84.interfaces;
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
public interface WindowManagement extends PICComponentInterface {
|
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
||||||
|
|
||||||
|
public interface WindowManagement extends PICComponentInterface, FrontendSpecificObject {
|
||||||
static void refreshTable() {}
|
static void refreshTable() {}
|
||||||
|
|
||||||
static void startFromMain(String[] args) {}
|
static void startFromMain(String[] args) {}
|
||||||
|
|||||||
@ -47,6 +47,9 @@ class EEPROMTests {
|
|||||||
DataRegisterInterface mockDataRegister = Mockito.mock(DataRegisterInterface.class);
|
DataRegisterInterface mockDataRegister = Mockito.mock(DataRegisterInterface.class);
|
||||||
picComponents.registerComponent(DataRegisterInterface.class, mockDataRegister);
|
picComponents.registerComponent(DataRegisterInterface.class, mockDataRegister);
|
||||||
|
|
||||||
|
ExecutionTimeSubject mockExecutionTime = mock(ExecutionTimeSubject.class);
|
||||||
|
picComponents.registerComponent(ExecutionTimeSubject.class, mockExecutionTime);
|
||||||
|
|
||||||
EEPROMInterface eeprom = new EEPROM();
|
EEPROMInterface eeprom = new EEPROM();
|
||||||
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
||||||
picComponents.initAll();
|
picComponents.initAll();
|
||||||
@ -97,6 +100,9 @@ class EEPROMTests {
|
|||||||
CommandInterface mockCommands = mock(CommandInterface.class);
|
CommandInterface mockCommands = mock(CommandInterface.class);
|
||||||
picComponents.registerComponent(CommandInterface.class, mockCommands);
|
picComponents.registerComponent(CommandInterface.class, mockCommands);
|
||||||
|
|
||||||
|
ExecutionTimeSubject mockExecutionTime = mock(ExecutionTimeSubject.class);
|
||||||
|
picComponents.registerComponent(ExecutionTimeSubject.class, mockExecutionTime);
|
||||||
|
|
||||||
EEPROMInterface eeprom = new EEPROM();
|
EEPROMInterface eeprom = new EEPROM();
|
||||||
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
||||||
picComponents.initAll();
|
picComponents.initAll();
|
||||||
@ -122,6 +128,9 @@ class EEPROMTests {
|
|||||||
CommandInterface mockCommands = mock(CommandInterface.class);
|
CommandInterface mockCommands = mock(CommandInterface.class);
|
||||||
picComponents.registerComponent(CommandInterface.class, mockCommands);
|
picComponents.registerComponent(CommandInterface.class, mockCommands);
|
||||||
|
|
||||||
|
ExecutionTimeSubject mockExecutionTime = mock(ExecutionTimeSubject.class);
|
||||||
|
picComponents.registerComponent(ExecutionTimeSubject.class, mockExecutionTime);
|
||||||
|
|
||||||
EEPROMInterface eeprom = new EEPROM();
|
EEPROMInterface eeprom = new EEPROM();
|
||||||
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
||||||
picComponents.initAll();
|
picComponents.initAll();
|
||||||
|
|||||||
Reference in New Issue
Block a user