A study project implementing the classic GoF (Gang of Four) design patterns in modern Dart 3 with sound null safety.
Each pattern lives in its own folder under lib/, with focused unit tests
under test/. The file bin/main.dart contains a runnable demo of every
pattern.
| Pattern | Folder | Description |
|---|---|---|
| Singleton | lib/creational/singleton |
Guarantees a single instance with a global access point. |
| Factory Method | lib/creational/factory |
Creates currency objects based on a country, without exposing the instantiation logic. |
| Builder | lib/creational/builder |
Step-by-step construction of a Pizza object with optional toppings. |
| Pattern | Folder | Description |
|---|---|---|
| Adapter | lib/structural/adapter |
Bridges a legacy LegacyPrinter to the modern ModernPrinter interface. |
| Bridge | lib/structural/bridge |
Decouples a RemoteControl abstraction from TV/Radio implementations. |
| Decorator | lib/structural/decorator |
Wraps ice creams with toppings, accumulating price dynamically. |
| Facade | lib/structural/facade |
Hides the complexity of booting a computer (CPU + memory + hard drive) behind a single start(). |
| Pattern | Folder | Description |
|---|---|---|
| Command | lib/behavioral/command |
Encapsulates light on/off requests as objects with undo support. |
| Chain of Responsibility | lib/behavioral/chain_of_responsibility |
Routes authorization requests through a chain of role-based handlers. |
| Observer | lib/behavioral/observer |
A singleton Subject (event bus) that notifies registered callbacks. |
| State | lib/behavioral/state |
A media player whose play/pause behaviour changes with its state. |
| Strategy | lib/behavioral/strategy |
Fighters with swappable kick/jump/punch behaviours. |
| Template Method | lib/behavioral/template_method |
Skeleton for preparing hot beverages, with overridable steps and a hook. |
Requires the Dart 3 SDK (>=3.0.0).
# install dependencies
dart pub get
# run the demo (all patterns)
dart run
# run the full test suite
dart test
# static analysis
dart analyzedart_design_patterns/
├── bin/
│ └── main.dart # runnable demo of every pattern
├── lib/
│ ├── creational/ # ── Creational patterns ──
│ │ ├── builder/ # Builder
│ │ ├── factory/ # Factory Method
│ │ └── singleton/ # Singleton
│ ├── structural/ # ── Structural patterns ──
│ │ ├── adapter/ # Adapter
│ │ ├── bridge/ # Bridge
│ │ ├── decorator/ # Decorator
│ │ └── facade/ # Facade
│ └── behavioral/ # ── Behavioral patterns ──
│ ├── chain_of_responsibility/ # Chain of Responsibility
│ ├── command/ # Command
│ ├── observer/ # Observer / Subject
│ ├── state/ # State
│ ├── strategy/ # Strategy
│ └── template_method/ # Template Method
└── test/ # unit tests (one file per pattern)
- Dart 3 with sound null safety (
sdk: '>=3.0.0 <4.0.0'). - File names follow
snake_case.dart. - Linting via
package:lintsrecommended rules. - Tests use
package:test.
Released under the MIT License.