design-patterns

Provide Java code examples for creational, structural, and behavioral design patterns.

23|7|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/hzy970907/fish-claude-code --skill design-patterns-hzy970907
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: design-patterns
Source: https://github.com/hzy970907/fish-claude-code/tree/main/skills/design-patterns
Command: npx skills add https://github.com/hzy970907/fish-claude-code --skill design-patterns-hzy970907

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides clear, practical examples of common Java design patterns, helping developers write more maintainable, scalable, and robust code.

Core Features & Use Cases

  • Pattern Implementation: Offers code examples for Creational (Builder, Factory, Singleton), Structural (Decorator, Adapter), and Behavioral (Strategy, Observer, Template Method) patterns.
  • Use Case: When designing a new feature that requires flexible algorithm selection, use the Strategy pattern examples to implement interchangeable payment methods.

Quick Start

Show me how to implement the Builder pattern for a User object.

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 for a Java object?

To implement the Builder pattern for a Java object, construct a static inner Builder class within your target object to set optional parameters and provide a build method to return the finalized instance. This pattern simplifies constructing complex objects with multiple parameters.

When should I use behavioral design patterns like Strategy in Java?

Use behavioral design patterns like Strategy in Java when designing a feature requiring flexible algorithm selection, such as implementing interchangeable payment methods. This approach encapsulates algorithms as separate classes, allowing runtime swapping without altering the client context.

What Java design patterns are available for code refactoring?

Available Java design patterns for code refactoring include Creational patterns like Builder, Factory, and Singleton, Structural patterns like Decorator and Adapter, and Behavioral patterns like Strategy, Observer, and Template Method to improve maintainability and scalability.

How do structural patterns like Decorator and Adapter work in Java?

Structural patterns like Decorator and Adapter work in Java by composing objects to add responsibilities or bridging incompatible interfaces. Decorator wraps objects to extend behavior dynamically, while Adapter converts a class interface to match client expectations.

Can I use the Singleton pattern to ensure a single instance in Java?

Yes, you can use the Singleton pattern to ensure a single instance in Java by restricting class instantiation through a private constructor and exposing a static method to provide global access to that one created instance.

What is the best way to implement interchangeable algorithms for object-oriented problem-solving?

The best way to implement interchangeable algorithms for object-oriented problem-solving is using the Strategy pattern. It defines a family of algorithms, encapsulates each one, and makes them interchangeable within a given context, promoting scalable code.