Skip to content
Back to skills

Design Patterns Skill

ASecurity

Apply GoF design patterns (Creational, Structural, Behavioral) appropriately without over-engineering - language-agnostic with practical examples

  • 6 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 20, 2026
devopsgosqlnoderefactoringapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned September 20, 2026

npx -y skills add darellchua2/opencode-config-template --skill design-patterns-skill --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Design Patterns Skill?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Design Patterns Skill
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/darellchua2-design-patterns-skill/badge)](https://www.skillsdirectory.com/skills/darellchua2-design-patterns-skill)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: design-patterns-skill
description: Apply GoF design patterns (Creational, Structural, Behavioral) appropriately without over-engineering - language-agnostic with practical examples
license: Apache-2.0
compatibility: opencode
category: Code Quality
---

## What I do

Apply design patterns where they fit — and refuse to force them. Patterns solve problems you HAVE, not problems you MIGHT have; let them emerge from refactoring, not upfront design.

## When to use me

- A design problem you recognize (repeated type-switching, behavior addable without modification, complex object construction)
- You're tempted to add a pattern and want a second opinion on whether it's warranted

## House Learnings

#### Learning: `zai-client-class`
Instead of per-endpoint adapters, wrap all API endpoints in a single client class handling key resolution, base URL config, and error mapping centrally (combined Adapter + Facade): one `ZaiClient` with `_headers()`/`_request()` internals and typed endpoint methods (`search`, `summarize`, `analyze`); missing `ZAI_API_KEY` raises at construction.

#### Learning: `enum-strategy-resolution`
Dispatch via `str` + `Enum` with a default member: one dispatch point, Open/Closed-compliant (new strategies need no dispatcher edit), callers pass raw strings or enum members interchangeably. Unknown values fall through to the `UNKNOWN` member's handler instead of raising.

### Learning: `atomic-sql-update-race-free-transition`
Use a single `UPDATE ... WHERE expected_state RETURNING cols` as an optimistic lock — the `WHERE` guards the transition, `RETURNING` fetches columns in one round-trip, losers re-read and reconcile idempotently. Never read-then-write state transitions (two workers both commit, duplicate side effects).
Detection: `rg 'get_.*\(|fetch_.*\(' --type py -A 10 | rg 'status|state' | rg 'commit|save|update'`

### Learning: `double-checked-locking-async-refresh`
Async token/cache refresh must use double-checked locking (unlocked check → acquire lock → RE-CHECK → refresh only if still invalid) so exactly ONE caller hits the upstream provider per expiry window; hot path stays lock-free. Pair with `time.monotonic()` (NTP-immune) and proactive refresh at 80% of TTL.
Detection: `rg 'async with self\._lock|async with.*Lock' --type py -A 15 | rg 'await.*refresh|await.*fetch' | rg -v 'if.*stale|if.*expired'`

#### Learning: `zai-node-mixin`
Prefer mixins over deep inheritance for selectively adopted behaviors: a `CacheMixin`/`RetryMixin` composing into `DataPipeline` respects `__init_subclass__`, avoids fragile-base-class coupling, and subclasses pick only what they need.

> Removed 2026-09: GoF catalog with per-pattern code examples (Singleton/Factory/Builder/Adapter/Decorator/Proxy/Strategy/Observer/Template Method/Command), pattern-selection table, anti-pattern table, steps/best-practices/verification ceremony — textbook the model knows; the five codified learnings above are this config's real additions.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…