Java Omnibus
OOAD & Architecture / Reference & Downloads / Java GoF Patterns Source Code
Downloads GoF Source Code Java
Reference & Downloads

Source-code packs are most useful when they show patterns in one connected domain instead of as disconnected toy fragments.

This page organizes a practical source-code study pack for GoF patterns using the same order-management domain used throughout the vertical. The goal is to make comparative study easier: you should be able to see how Strategy, Adapter, Builder, State, Decorator, and others look when they live in the same conceptual world.

Why This Topic Matters

Why it matters in real Java systems

Developers often understand patterns faster when they can compare multiple examples side by side in one domain model. This page acts as a download-style index and study plan for building or reviewing a reusable source pack.

Core Explanation

The main reference idea

The recommended layout groups examples by family and keeps one shared domain package for common types such as Order, Payment, Shipment, and Notification. That way the patterns feel like alternative design moves inside one product instead of isolated classroom sketches.

Concept Breakdown

Key ideas to keep in mind

Reference

Creational pack

Factory Method, Abstract Factory, Builder, Prototype, and Singleton examples around domain object creation.

Reference

Structural pack

Adapter, Facade, Decorator, Proxy, Bridge, and Composite in realistic integration and UI-support scenarios.

Reference

Behavioral pack

Strategy, State, Command, Observer, Template Method, and related examples tied to workflows and policies.

Suggested source-pack structure

Suggested source-pack structure

Suggested package layout
org.javaomnibus.examples.gof
├── common
│   ├── order
│   ├── payment
│   ├── shipment
│   └── notification
├── creational
├── structural
└── behavioral
Java Example

Java example in the Order Management domain

Java example: shared domain type used across pattern examples
package org.javaomnibus.examples.gof.common.order;

public record OrderId(String value) {}

public record OrderLine(String productCode, int quantity) {}
Code Walkthrough

Step by step

  1. The point is not complexity. It is reuse across many pattern examples.
  2. A shared domain core makes the example pack easier to compare and maintain.
  3. This is more educational than writing twenty unrelated toy examples.
  4. That is why the vertical has stayed with one e-commerce story throughout.
Real-World Usage

Where this helps in practice

  • Pattern workshops
  • Internal teaching repositories
  • Hands-on revision for interviews or architecture onboarding
Trade-Offs

Trade-offs and when to be careful

  • Connected example packs improve learning, but they take more authoring discipline than isolated snippets.
  • The payoff is stronger long-term recall and easier side-by-side comparison.
Common Mistakes

Frequent mistakes to watch for

  • Using unrelated toy domains for each pattern
  • Changing naming and style across every example
  • Forgetting to explain why one pattern was chosen over a nearby alternative
  • Publishing examples with no guidance about what pressure each pattern solves
Related Pages

Related concepts


What To Read Next