Java Design Patterns

Guides implementation of creational, structural, and behavioral design patterns in Java Spring Boot.

Updated May 12, 2026
One-click install
npx skills add https://github.com/ZzZueszZ/claude-kit --skill java-design-patterns-zzzueszz
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: Java Design Patterns
Source: https://github.com/ZzZueszZ/claude-kit/tree/main/.claude/skills/java-design-patterns
Command: npx skills add https://github.com/ZzZueszZ/claude-kit --skill java-design-patterns-zzzueszz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Developers often struggle to decide when and how to apply design patterns in Java Spring Boot projects, leading to over-engineering, rigid if/else chains, or tightly coupled code that is hard to extend and test. ## Core Features & Use Cases - Pattern Catalog with Spring Context: Covers Builder, Factory Method, Singleton, Adapter, Decorator, Facade, Strategy, Template Method, Observer (Spring Events), and Chain of Responsibility with runnable Spring Boot code examples. - Decision Guidance: Each pattern includes class diagrams, when-to-use vs when-not-to-use tables, and comparisons (e.g., Strategy vs Factory vs if/else, Decorator vs AOP) to prevent misuse. - Use Case: When building a notification system with email, SMS, and push channels, use the Spring auto-collecting Factory pattern so adding a new channel requires only a new @Component class without modifying existing code. ## Quick Start Ask the assistant to show how to refactor a growing if/else discount calculation into the Strategy pattern in a Spring Boot service.

Frequently Asked Questions about Java Design Patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement the Factory pattern in Spring Boot?▼

Define an interface with a getType method, annotate each implementation with @Component, then inject List<Interface> into a factory class. Spring auto-collects all implementations into a Map keyed by type, so new implementations require no factory changes.

What is the difference between Strategy and Factory patterns in Java?▼

Factory creates different objects based on a condition, while Strategy selects different behaviors for the same task at runtime. Both can use Spring's list injection to auto-collect implementations and avoid if/else chains.

Should I use Decorator or Spring AOP for adding behavior?▼

Use Decorator for business-level wrapping like adding tax or discounts to a calculation, where explicit control matters. Use Spring AOP for cross-cutting concerns such as logging, security, and auditing that span many components.

Do I need to implement Singleton manually in Spring Boot?▼

No. Spring beans are singletons by default within the ApplicationContext, so manual getInstance implementations are unnecessary. Be careful with mutable fields in singleton beans, since shared state can cause race conditions.

When should I use @EventListener versus @TransactionalEventListener?▼

Use @EventListener for side effects that can run immediately within the same transaction. Use @TransactionalEventListener with AFTER_COMMIT when the handler depends on data being successfully persisted, such as assigning roles after user creation.

When should I avoid using design patterns in Java?▼

Avoid patterns when a simpler construct suffices: skip Factory for a single implementation, skip Strategy for one or two fixed cases, and skip Builder for POJOs with one or two fields. Patterns should solve real problems, not follow best practice blindly.