Three Java Swing applications illustrate the Decorator and Observer patterns:
- Classic — original CSC308
decoratedChart, using deprecatedjava.util.ObservableandObserver, a rolling 20-value window, and four decorated charts. Entry point:edu.plotter.classic.World. - Legacy — original CSC308
gradePlotterApp, preserved for UML reverse engineering and refactoring. Entry point:edu.plotter.legacy.Main. - Modern — the existing
edu-plotterimplementation usingPropertyChangeSupport, a Singleton repository, and three decorated plots. Entry point:edu.plotter.modern.Main.
Compile with mvn compile, then run the desired entry point from your IDE. The classic Observer API is intentionally preserved for historical comparison. Compare observer registration, state management, and decorator composition between versions.
A small Java Swing application that demonstrates how Decorator, Observer, and Singleton can collaborate to visualize a changing collection of values.
Requires JDK 17+ and Maven 3.9+.
mvn clean package
mvn exec:javaA window opens with three plots. Click Run to generate a new value. All three panels update together and display the same data with different decorations.
- Decorator:
Componentdefines drawing;Plotdraws the line, whileSquareBlueandBarGrayadd visual layers without changingPlot. - Observer:
Repositoryemits property-change events when data changes. EachPlotPanellistens and repaints. - Singleton:
Repository.getInstance()supplies one shared in-memory dataset for the three panels.
See the architecture diagram for relationships and the update flow.
src/main/java/edu/plotter/— the original plotting application, moved into a Java package.docs/architecture.md— Mermaid class and interaction diagrams.pom.xml— Maven build and run configuration.
This is a teaching example, not a production-ready charting library. The code intentionally preserves the original behavior and pattern implementation for discussion. Each class includes introductory JavaDoc describing its responsibility and role. Possible refactorings include using panel dimensions instead of hard-coded coordinates, preventing external mutation of stored values, using constructor injection for decorators, and improving singleton thread safety.
The earlier unrelated OLD/ examples are removed from the current branch but remain accessible in Git history.