design-patterns

Implements common Java design patterns with code examples and selection guidance.

Updated Dec 23, 2025
One-click install
npx skills add https://github.com/zuldare/apuntesIA --skill design-patterns-zuldare
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: design-patterns
Source: https://github.com/zuldare/apuntesIA/tree/main/skills/design-patterns
Command: npx skills add https://github.com/zuldare/apuntesIA --skill design-patterns-zuldare

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Choosing and correctly implementing the right design pattern in Java is error-prone, and developers often over-engineer solutions or pick the wrong pattern for their problem. ## Core Features & Use Cases - Pattern Reference with Code: Provides working Java implementations of Builder, Factory, Strategy, Observer, Decorator, and Adapter patterns, including Spring-based variants. - Selection Guidance: Decision tables map common problems (complex construction, runtime algorithm swapping, legacy integration) to the appropriate pattern. - Anti-Pattern Warnings: Flags common mistakes like Singleton abuse and overused factories, with better alternatives. - Use Case: When a user asks to "implement a factory for notification senders" or "refactor this to use the strategy pattern", the Skill supplies idiomatic Java or Spring code ready to adapt. ## Quick Start Ask the assistant to implement the strategy pattern for a payment system in Java using this design patterns reference.

Frequently Asked Questions about design-patterns

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

FAQPage Schema
How do I implement the Builder pattern in Java?▼

Create a static nested Builder class holding the same fields, make the outer constructor private, and expose a fluent API where each setter returns the builder and build() constructs the object. This avoids telescoping constructors when many parameters are optional.

When should I use Factory vs Builder pattern?▼

Use Builder when constructing one complex object with many optional parameters. Use Factory when the exact class to instantiate is determined at runtime, such as selecting a notification sender by type string.

How do I implement the Observer pattern in Spring Boot?▼

Publish events with ApplicationEventPublisher and consume them with @EventListener annotated methods on Spring components. Adding @Async lets listeners like email senders run without blocking the publisher.

Can the Strategy pattern be written with Java lambdas?▼

Yes. Define the strategy as a @FunctionalInterface with a single method, then pass lambdas or method references as implementations. This removes the need for separate concrete strategy classes for simple behaviors.

What are common design pattern anti-patterns to avoid?▼

Avoid Singleton abuse, which creates global state and hinders testing; prefer dependency injection. Avoid factories when the type is known at compile time, and keep decorator chains short to remain debuggable.