yonatankarp/software-design-skills

gof-template-method

Use when an algorithm has a fixed skeleton with variable steps — phrases like "Template Method pattern", "the steps are the same but one varies", "Coffee and Tea both brew via boil-brew-pour-add-condiments but differ in two steps", "hook method", "the Holly…

소스 보기

사용 방법

  1. 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
  2. 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
  3. 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
npx skills add https://github.com/yonatankarp/software-design-skills --skill gof-template-method

시작 전 확인

  • 설치에는 모델 구독, API 한도, 파일 접근 권한이 포함되지 않습니다.
  • 별점 수와 설치 수는 활동 지표이며 독립적인 품질·보안 검증이 아닙니다.
원본 Skill 문서

원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.

One-line summary

Define the skeleton of an algorithm in a base method, deferring some steps to subclasses — letting subclasses redefine certain steps without changing the algorithm's structure.

When to use this skill

  • Two or more classes follow the same overall procedure but differ in one or two steps (Beck's "Coffee and Tea both brew" example).
  • A workflow has a fixed sequence but specific stages vary by use case (e.g., a parsing pipeline where the tokenize step differs per format).
  • Cross-cutting framework hooks: a base class provides lifecycle methods, subclasses override the ones they care about (Spring's JdbcTemplate, JUnit's setUp / tearDown).

When NOT to use this skill

  • The variation is the algorithm itself, not steps within a skeleton — that's gof-strategy.
  • Only one step varies and the variation is small — a function parameter or lambda is simpler than a subclass.
  • The base class becomes an inheritance choke point that prevents the subclass from doing anything outside the template — that's a sign the abstraction is too rigid.

Core content

A TemplateMethod is a (typically final or non-overridable) method on the base class that calls a sequence of steps, some implemented in the base, others abstract or "hook" methods that subclasses override.

base.run():
    step1()         # final, implemented in base
    step2Abstract() # abstract — subclass must provide
    step3Hook()    # default no-op — subclass may override
    step4()         # final, implemented in base

Three kinds of steps:

  • Concrete — fully implemented in the base class.
  • Abstract — subclass must implement.
  • Hook — default behavior (often a no-op or sensible default); subclass may override.

The "Hollywood Principle" — "don't call us, we'll call you" — is the framework-level expression of this pattern. The base class calls the subclass's overrides at the right moments; the subclass doesn't call the base class to drive the workflow.

Decision heuristics

  • Use when the skeleton is shared and the steps vary. If only one step varies, consider a function parameter instead of a subclass.
  • Make the template method final (or non-overridable) so subclasses can't break the workflow.
  • Distinguish abstract steps (must override) from hook steps (may override) — and document which is which.
  • If subclasses keep needing to override more and more steps to do non-trivial work, the template is too rigid.

Anti-patterns

  • Template Method where the "template" is a giant method with many overridable steps — the rigidity that makes Template Method valuable disappears.
  • Overriding the template method itself in a subclass — defeats the purpose.
  • Calling super.step1() from a subclass's overridden step — couples subclass to base internals.

See also

  • gof-strategy — when the whole algorithm varies, not just steps within it.
  • gof-factory — Factory Method is an instance of Template Method (the algorithm defers the choice of concrete type to a subclass).
  • gof-kotlin-idioms — Kotlin's open / final defaults make Template Method explicit, and higher-order functions often beat subclass-based templates for one or two varying steps.

References

  • Head First Design Patterns (2nd ed), Ch. 8 ("Encapsulating Algorithms: the Template Method Pattern") — canonical exposition with the Coffee/Tea example.

관련 작업

같은 저장소의 Skills

더 많은 Skills

모든 Skills
yonatankarp
커뮤니티

arch-adr

Use when recording an architectural decision so future maintainers know why — phrases like "ADR", "architecture decision record", "why did we pick X", "lightweight architecture documentation", "decision log", "should this be an ADR", "tribal knowledge", "we chose this two years ago and now nobody remembers why". Defines the ADR as a short, structured document capturing what was decided, why, alternatives considered, and consequences — written at the time of the decision and kept in the repo.

설치 수
2
GitHub Stars
1
업데이트
5월 19일
yonatankarp
커뮤니티

arch-fitness-functions

Use when enforcing architectural characteristics through automation — phrases like "architecture fitness function", "evolutionary architecture", "architecture tests", "ArchUnit", "dependency rules in CI", "automated architecture checks", "guardrails", "drift detection". Defines fitness functions as automated checks that verify architectural characteristics on every change, catching drift before it accumulates.

설치 수
2
GitHub Stars
1
업데이트
5월 19일
yonatankarp
커뮤니티

arch-microservices

Use when designing or reviewing a microservices architecture — phrases like "microservices", "should we split this service", "service boundaries", "bounded context per service", "API gateway", "backend for frontend", "BFF", "service mesh", "microservices vs monolith", "database per service", "data ownership". Defines microservices as independently deployable services aligned with business capabilities — and the discipline of resisting the style until the monolith proves inadequate.

설치 수
2
GitHub Stars
1
업데이트
5월 19일
yonatankarp
커뮤니티

arch-strangler-fig

Use when migrating a legacy system incrementally — phrases like "strangler fig", "strangler pattern", "incremental migration", "monolith to microservices", "rewrite without big bang", "replace legacy in place", "facade in front of the legacy system", "anticorruption layer". Defines Fowler's Strangler Fig as the migration discipline of gradually replacing legacy functionality behind a stable facade, never doing a big-bang rewrite.

설치 수
2
GitHub Stars
1
업데이트
5월 19일