$ show iluwatar/java-design-patterns
This repository is a comprehensive catalog of software design pattern implementations in Java, maintained by Ilkka Seppรคlรค (iluwatar). It contains over 300 self-contained modules, each demonstrating a classic GoF pattern, architectural pattern, concurrency pattern, or microservices pattern. The code is educational and demonstrative rather than production-ready, with each module providing a runnable App.java entry point, clear class hierarchies, and accompanying unit tests. The project serves as a reference for developers learning design patterns, and the implementations are intentionally simplified to focus on the pattern's mechanics. The architecture is modular: each pattern lives in its own Maven module with a consistent structure (main source, test source, documentation images, and localized READMEs). Some modules integrate with Spring Boot, JPA/Hibernate, Kafka, or MongoDB for realistic context, but the vast majority use in-memory data structures. The codebase spans Java 8 to modern features, with extensive use of Lombok, SLF4J, and JUnit 5. While not a single deployable application, the repository effectively demonstrates how patterns solve common design problems. Notable for both its breadth and craftsmanship, the repository includes patterns from creational (Builder, Factory), structural (Adapter, Proxy), behavioral (Observer, Strategy), and architectural (Hexagonal, Clean Architecture) categories. Many modules implement reusable abstractions (e.g., Converter, Specification, Filterer, EventDispatcher) that can be extracted and used in new projects. The project's high star count and active contributor base reflect its status as a primary learning resource for Java design patterns.
The LLM identified 5 files worth highlighting for reuse:
A lightweight HTTP client that uses Java's dynamic proxy to convert interface method calls into REST API requests. It reads annotations like @Get, @Post, @Path, @Body from the interface and dynamically constructs and executes HTTP requests. This implementation is self-contained (only depends on Java standard library for proxying and basic HTTP) and demonstrates non-obvious use of reflection and dynamic proxies for boilerplate reduction. It can be extracted as a standalone library for simple REST clients.
An event journal implementation that serializes domain events to a JSON file. It supports appending events and replaying them to rebuild state. The class is isolated, uses Jackson for JSON, and follows the Event Sourcing pattern cleanly. It can be reused in any event-sourced system as a simple file-based journal, demonstrating a practical, lightweight alternative to databases for small-scale event stores.
A generic functional interface that enables type-safe, composable filtering on collections of objects. It defines a method that takes a predicate and returns a filtered version of the container, preserving type information. This pattern avoids common pitfalls like casting or losing generic types. The interface is reusable across any domain where filtered views of collections are needed, and it demonstrates a non-obvious approach to maintaining type safety while filtering.
Abstract base class for the Specification pattern, providing default implementations for logical combinators (and, or, not) as well as a null-safe isSatisfiedBy method. Subclasses only need to implement an abstract `test` method. This class is fully extracted from business logic and can be reused in any project that needs composable business rules. It demonstrates clean application of the Composite pattern over boolean logic.
A generic bidirectional converter that maps between a domain entity and a DTO. It uses Java generics to enforce type safety and provides default implementations for converting collections and lists. The class is a single abstract file with no dependencies beyond Java core, making it a textbook example of a reusable data mapping utility. It can be dropped into any project that needs DTO/entity conversion without framework overhead.